✓ Accepted answer
You can use a recursive function, a function that calls itself from within itself as such:
local Amount = game:GetService("ReplicatedStorage"):WaitForChild("Amount")
local function BeginTimer()
while wait(1) do
if Amount.Value < 5 then
BeginTimer()
break
end
for t = 20,0,-1 do
print(t)
wait(1)
end
end
end)
BeginTimer()
However, I'm not sure this is the behaviour you're expecting. This will cause the loop to reset every 20 seconds, no matter what Amount.Value is. Incase you want this to occur only once each time the value goes below 5, you can listen for changes and then start the timer:
local Amount = game:GetService("ReplicatedStorage"):WaitForChild("Amount")
local timerOff = true
Amount.Changed:Connect(function()
if Amount.Value < 5 and timerOff then
timerOff = false
for t = 20,0,-1 do
print(t)
wait(1)
end
timerOff = true
end
end)
1 comment
thanks