I am assigning an object to objectvalue and then using it on a script but when I run it returns nil, how can I fix this ?
try doing wait function for .3 seconds before the script prints
it’s not recommended to put an ObjectValue’s value to an instance that is a descendant of StarterGui, as when the gui is cloned, your cloned ObjectValue’s value will point to the one still in StarterGui, and not the object you were probably intending for it to reference (the one that would be in PlayerGui)
Instead of this I’d recommend doing:
script.Parent:WaitForChild("Value")
This will wait until the instance has loaded before attempting to execute the line of code, instead of an arbitrary 0.3 second wait (which could still potentially fail).
To any new visitors doing Advanced Scripting:
If you are trying to read the ObjectValue.Value and still returns nil, try reparenting the object value to the workspace or any descendant in the workspace first, and then run your actual code.
In fact, if by any means you previously reallocated the ObjectValue to some parent such as ServerScriptService or you went WILD and sent it to NIL to then bring it back, the value will actually take a few seconds to load the previously stored/saved Value, even if it was saved for AGES beforehand.