How To Index Reserved Table?

Is it possible to add a function to a luau reserved table like “Instance”

For Example:

Instance.newPart = function()
	local Part ="Part")
	return Part

No, you are prevented from doing this in order to stop you accidentally creating Spooky Action.

1 Like

No, ever since table.freeze was released, Roblox started freezing these tables. Before that, they were using metatables to achieve a similar read-only effect (this practice began around 2012, when they started taking the security of these APIs more seriously).

print(table.isfrozen(Instance)) --> true

If you really wanted to, you could overwrite the global variable with a new object that wraps the old table. However, the script editor (for good reason) will give you a warning if you attempt this.

	local OldNew =
	Instance = setmetatable({
		NewPart = function()
			return OldNew("Part")
	}, {__index = Instance})

print(Instance.NewPart()) --> Part
print("Part")) --> Part

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.