Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is this happening?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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?

1 answer

Log in to vote
6
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

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.

Ad

Answer this question