In a script I'm working on, I have a line of code that fires after it confirms a value inside a Frame exists. Here's the line of code:
repeat wait() until script.Parent.Value -- code here
The problem, though, is that even when it checks if it's not nil, the script breaks. The output reads:
:1:Value is not a valid member of Frame
Also, putting something like:
local value = script.Parent:findFirstChild("Value") repeat wait() until value
just puts the script in an infinite loop, even if the value isn't nil. Can somebody please explain why the script is breaking?
Your loop doesn't change the variable value
, so if value
was nil
at the beginning, it will always be loop forever after.
repeat wait() until script.Parent:FindFirstChild("Value")
Conveniently, ROBLOX provides a :WaitForChild
method that acts like :FindFirstChild
except that it will pause until there actually is such an object, hence
thevalue = script.Parent:WaitForChild("Value")
should suffice.