I want to pause this countdown once the flow is no longer happening, this is my script but it still keeps counting down
airlabel = script.Parent.AirLabel
on = script.Parent.AirLabel.On
off = script.Parent.AirLabel.Off
flow = false
on.MouseButton1Click:Connect(function()
if flow == false then
for i = 100, 0, -3 do
airlabel.Text = i
wait(1)
flow = true
if flow == false then
repeat wait() until flow == true
end
end
end
end)
off.MouseButton1Click:Connect(function()
if flow == true then
flow = false
end
end)
To pause the countdown, you can add a repeat...until loop in your on.MouseButton1Click function that waits until flow is set to true. For example
airlabel = script.Parent.AirLabel
on = script.Parent.AirLabel.On
off = script.Parent.AirLabel.Off
flow = false
on.MouseButton1Click:Connect(function()
if flow == false then
for i = 100, 0, -3 do
airlabel.Text = i
wait(1)
flow = true
if flow == false then
repeat wait() until flow == true
end
end
end
end)
off.MouseButton1Click:Connect(function()
if flow == true then
flow = false
end
end)
This will pause the countdown when the off button is clicked and resume it when the on button is clicked again. Your code is kinda messed up
Use task.wait (just write task. Before wait)
Don’t use repeat until value. Add the value in workspace and use .Changed. it does the same thing except it’s using less resources.
Also, if you need the player’s character (pretty unrelated), instead of using repeat do:
local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait() --basically, it assigns the character, but if it doesn't exist it'd error, but it sees the or. :Wait is basically connect except for the fact it waits until the event fires, and then it continues. No functions and only fires once since it just yields.