ReferenceMetatables

getrawmetatable

Returns a value's metatable directly, ignoring any __metatable protection.

Syntax

getrawmetatable(object: any) -> table?

Also available as

debug.getmetatableget_raw_metatable

Parameters

ParameterTypeDescription
objectanyAny value: a table, an Instance, a string, a userdata.

Returns

TypeDescription
table?The value's metatable, or nil when it has none.

Description

getmetatable returns the __metatable field instead of the real metatable when one is set, which is how Instances hide theirs: getmetatable(game) returns the string "The metatable is locked". getrawmetatable always returns the real table, so you can read the metamethods behind it.

Example

local mt = getrawmetatable(game)
print(getmetatable(game))
print(type(mt.__index), type(mt.__namecall))

print(getrawmetatable("text").__index == string)

Notes

These are Game executor contracts. Check build requirements and session lifetimes before using them.