I am honestly a bit confused here.
I won’t make this very long cause 1) there’s not alot to it
and 2) it might be me who missed an obvious detail.
I have this little code right here to test what was wrong with the while loop, as it wasn’t working in my script:
It prints what I change the “test” value to, so I can see that it is detectable, which it was, as it printed 5.
But then the loop was supposed to constantly print “yes” every second when the test value is higher than 0, which we can see it clearly is.
But it did not print anything, so something is stopping the loop from running.
Does anybody know why this is happening?
From what I can see in this example of it here, the code should be working?
The value gets changed from a different server-script.
Oh, so when it is 0 or below, it stops permanently?
How would I make it stop and start depending on the value then?
Will I have it make it run on a while true do loop and constantly check what the value is?
Yes, depending on how your system is setup you could wait for it to get changed first:
local test = script.Parent:WaitForChild("FireTimer", 10)
test.Changed:Wait()
while test.Value > 0 do
wait(1)
print("yes")
end
But if you want it to reset once it reaches 0 then it gets a bit more complicated:
local test = script.Parent:WaitForChild("FireTimer", 10)
local function ConnectListener()
local connection
connection = test:GetPropertyChangedSignal("Value"):Connect(function()
connection:Disconnect()
print("Start")
while (test.Value > 0) do
print(test.Value)
test.Value = test.Value - 1
wait(1)
end
print("Finish")
ConnectListener()
end)
end
ConnectListener()
The loop is going to fire whenever the value is above 0, and then the thought was to minus the number by one every second until it reaches 0 again, while it will then “rest” and wait until another script adds to the number again.
It is for a fire effect. When you get hit with fire, the value goes up, then it slowly goes down every second, and once it reaches 0, it should stop. (And the fire would be put out.)