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

Why does this loop only works twice?

Asked by 5 years ago
Edited 5 years ago
    while true do
        wait()
        if v.Value ~= 1 then
            print("bye")
    repeat wait() until v.Value == 1
end
end

At the beginning, it was working once. Now, this loop works for 2 times and then it stops responding to anything. In studio, it works normally. The script is a LocalScript.

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

Well, you shouldn't be using a loop to check if a property has changed. This is why the Changed event exists, to check if a property changes. The good thing is that the Changed event fires only when a property changes, so no code is running every 0.0299 seconds or however long the default wait time is.

v.Changed:Connect(function()
    wait() 

    if v.Value ~= 1 then
        print("bye")
     end
end)
Ad

Answer this question