Saving a instance in a dict

Is there anyway to insert a Instance in a dictionary,
i’ve tried but when i trie to acess the value says that the value its nil:

local Dict = {
        ["Key"] = {
               Dire = game.ReplicatedStorage.Instance
        }

}

May I see how did you try to access it?

local Dict = {
        ["Key"] = {
               Dire = game:GetService("ReplicatedStorage"):WaitForChild("Instance");
        }

}

Give this a try?

How are you trying to reference this object
Where are you referencing this object
What are you doing with the object once you have it

1 Like

How are you trying to reference this object?

local R = Dict["Key"].Dire

Where are you referencing this object?
in a local function inside a local script
What are you doing with the object once you have it?
nothing

When you have instances in a dictionary, those are references. Referencing an instance in a dictionary is as simple as having a key defined as the reference to that instance. You can also access it back by indexing the key to which the instance reference is assigned to. If you’re getting nil back, the reference doesn’t exist.

Noting that you said you are trying to access the reference from a LocalScript, does a LocalScript also set that entry in the dictionary? If that’s good, what of the instance, is it in a container replicated to the client? If neither of these are true, you’ll get back nil. Server actions in a ModuleScript do not replicate and server-side instances cannot be referenced by the client.

1 Like