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

Script is not detecting NumberValue change ? Game Script Timeout?

Asked by 4 years ago

So I put a part in Workspace, then I put a NumberValue inside of the part.

I put this script in the NumberValue:

while true do if script.Parent.Value == 0 then print("It's zero") wait(5) end end

I did this hoping that when the NumberValue changed to 0 that it would print "It's Zero" but when i run the game i get the error "Game Script timeout".

1 answer

Log in to vote
0
Answered by
U_srname 152
4 years ago

Change the script to this:

script.Parent:GetPropertyChangedSignal('Value'):Connect(function()
    if script.Parent.Value == 0 then
        print('It\'s Zero')
    end
end)

Now it will only run the code when the value is changed. Just be sure that when testing, go into server mode and edit the value there, or make a script to control that!

Ad

Answer this question