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

Is there a way to yield the thread until something happens? [closed]

Asked by
Minifig77 190
10 years ago

Is there any way to yield the current thread until something happens?

For example,

game.Workspace:WaitForChild("Part")

will yield the thread until a child named 'Part' is added. Is there any other way to yield the thread?

0
Anyone? Minifig77 190 — 10y

Locked by adark and Shawnyg

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
Defaultio 160
10 years ago

You could do something like

while true do
    newPart=Workspace.ChildAdded:Wait()
    if newPart.Name=="Part" then
        break
    end
end

Hope this helps.

Ad
Log in to vote
-3
Answered by 10 years ago

Yes, there is. You can use "repeat". For example:

repeat
--whatever code you want to repeat
until
x.Value == 30 --change this to whatever you want it to repeat until

I hope that answers your question! If so, please upvote and accept this answer.

0
This code will crash the game, as there is no wait() in the body of the repeat. As well, this is a laggy, busywait. Use Defaultio's method instead. adark 5487 — 10y