Is there a function equivalent of :WaitForChild() for dictionaries?
For example, I’d like to achieve something like this:
local dictionary = {}
spawn(function()
wait(2)
dictionary.ForeverHD = "Hello world"
end)
local value = dictionary.ForeverHD or dictionary:WaitForChild("ForeverHD")
print(value)
At the moment, my best option is doing this:
local dictionary = {}
local function getValue(valueName)
if not dictionary[valueName] then
repeat
wait()
until dictionary[valueName]
end
return dictionary[valueName]
end
spawn(function()
wait(2)
dictionary.ForeverHD = "Hello world"
end)
local value = getValue("ForeverHD")
print(value)
I don’t see why you would ever need to do this. You are setting the value somewhere else in your code, so you already know when it’s going to appear and what it’s going to be.
You are in control of creating keys in that dictionary, so you should already be aware of when any key is or is not set. It doesn’t make much sense to need something like this. What are you trying to do with this exactly?
I store some values in a module script in ReplicatedStorage. These values are only added in and updated by the server. In ReplicatedFirst I have a LocalScript which needs these values hence the need to wait for them.
The returned value from require(repStore.SomeModule) on the server is not the same as the return value from require(repStore.SomeModule) on the client, or as between clients. It sounds like this is the bigger issue here.
In other cases you can use bindable events or you can use setters, updaters, or proxy tables so that things get called when changing its value. Also, the modules are supposed to work like that otherwise it would be a major security flaw.