How do I store tables/booleans inside instances?

Hello there,

I want to store a table of data or a toggled value into a Instance, so that all scripts can access that data, but I have no idea how. I heard somewhere that I should use metatables, but I don’t understand metatables either.

Please help! Thank you for reading!

Elaborate on why you need to store tables inside instances?

You can use an instance as an index inside a table if that helps.

Table[instance] = {}

Just search metatables on the dev forum if you want to learn about those. It’s just functions called metamethods in a table that are called based on a situation. For example, __index is called when a script tries to index a value that doesn’t exist.

I want to store data (like if a light is on or off) in the object, so that all scripts can access that data

You may want to use a ModuleScript if multiple scripts may use it or a global value object (BoolValue for example).

1 Like