Where do I put Wait() function?

Hi, I’m just wondering where to put a wait() or task.wait() unction to pause the timer. I’ve tried putting it in multiple places, but the timer keeps counting. I’ve added a comment on the places I’ve tried to put it.

while true do
	--I've tried to add it here
	minutesvalue.Value = minutes
	secondsvalue.Value = seconds

	repeat
        --Here.
		if secondsvalue.Value <= 0 then
                        --Here too. Didn't work.
			minutesvalue.Value = minutesvalue.Value - 1
			secondsvalue.Value = 59
		else
			secondsvalue.Value = secondsvalue.Value - 1
		end
		wait(1)
		
		if secondsvalue.Value <= 0 and minutesvalue.Value <= 0 then
			game.Workspace.Ref.RefWhistle:Play()
			anim:Play()
			game.Workspace.Ref.GameOver:Play()
			game.Workspace.Gameover:FireAllClients()

			local red = game.Workspace.RedPoints
			local blue = game.Workspace.BluePoints

			local redwin = red.Value > blue.Value
			local bluewin = blue.Value > red.Value
			local tie = blue.Value == red.Value

			if redwin == true then
				game.Workspace.RedPoints.Value = 0
				game.Workspace.BluePoints.Value = 0
				game.Workspace.RedWins:FireAllClients()
				
				for i, v in pairs(game.Teams.Red:GetPlayers()) do
					v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value = v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value + 1
				end
			end

			if bluewin == true then
				game.Workspace.BlueWins:FireAllClients()
				game.Workspace.RedPoints.Value = 0
				game.Workspace.BluePoints.Value = 0
				for i, v in pairs(game.Teams.Blue:GetPlayers()) do
					v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value = v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value + 1
				end
			end

			if tie == true then
				game.Workspace.RedPoints.Value = 0
				game.Workspace.BluePoints.Value = 0
				game.Workspace.TieGame:FireAllClients()
			end
			for i, v in pairs(game.Players:GetPlayers()) do
				v.Character.HumanoidRootPart.CFrame = workspace.LobbyPart.CFrame
			end
			wait(60)
			
			game.Workspace.Ball.Position = Vector3.new(-2.5, 3.799, -4.5 )

			resetRed()
			resetBlue()
			game.Workspace.Ref.RefWhistle:Play()
		end
	until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
end
4 Likes

if you want the timer to be paused before each round then putting the wait([number]) at line 2 or 5 should work
im not quite sure what you are trying to do

3 Likes

I don’t know if this changes anything, but I forgot to clarify that it’s meant to run when a remote event fires.

workspace.BluePoint.OnServerEvent:Connect(function()
    wait(10)
end)

Something that looks like this: ^

2 Likes

is the while loop waiting for the remote event to fire before it starts a round?

3 Likes

Not yet, it should be able to repeat every second and check if the remote event is fired, if it is fired, it will run wait(10).

2 Likes

I am a bit lost of what you’re trying to do. What are you trying to achieve with this?

1 Like

You’ll have to use coroutines.

How about using for loops instead for round timers? I believe that for loops would work better with round timer or time in general. (from my experience)
Here maybe try:
while wait( time ) do ?
Hope this helps you somehow.

2 Likes

Adding on to @killer1200sah
For loops are great for timers especially when nested in functions if you want a continuous loop

This is a very crude example but works in the same way

function Timer(AmountOfTime)
for i = AmountOfTime, 0, -1 do
Timer = i
task.Wait(1)
end
Timer(60)
end

Timer(25)
1 Like

Thanks everyone for the help, I think I have not clearly clarified what I wanted to do.
The timer works great, counts down every 1 seconds.

What I’m trying to acheive is: When a certain remoteevent fires, stops the timer, it waits 10 seconds and then continues the timer.

It’s for a football (soccer) game. It’s meant to stop the counting down if there’s a goal, which is why it stops when a remote event fires.

The event is called:

workspace.BluePoint.OnServerEvent:Connect(function()

make a

VALUE.Changed:Connect(function()
while VALUE == true do
-- your code
end
end)
-- something that changes the VALUE boolean to true or false, it can be a boolean value object too

and it’s simple

1 Like

This is not what I asked for, this is simple code.

Where is the part the remote event fires?
Why would I need a value?

it’s classic block, when value is changed , the loop is starts, when this value is nil , loop stops

1 Like
workspace.BluePoint.OnServerEvent:Connect(function() wait(10) end)

should be put under the repeat if I am not mistaken

1 Like

If that doesn’t work then try to mess with booleans

like

local stoptimer = false
repeat
workspace.BluePoint.OnServerEvent:Connect(function() 
     stoptimer = true
end)

if stoptimer then
wait(10)
end
stoptimer = false
--Code
until secondsvalue.Value <= 0 and minutesvalue.Value <= 0

Didn’t work, as I have put in the script I’ve already tried that, I’ll try your other suggestion

1 Like
while true do
	--I've tried to add it here
	minutesvalue.Value = minutes
	secondsvalue.Value = seconds

	repeat
        --Here.
		if secondsvalue.Value <= 0 then
                        --Here too. Didn't work.
			minutesvalue.Value -= 1
			secondsvalue.Value = 59
		else
			secondsvalue.Value -= 1
		end
		wait(1)
		
		if secondsvalue.Value <= 0 and minutesvalue.Value <= 0 then
			game.Workspace.Ref.RefWhistle:Play()
			anim:Play()
			game.Workspace.Ref.GameOver:Play()
			game.Workspace.Gameover:FireAllClients()

			local red = game.Workspace.RedPoints
			local blue = game.Workspace.BluePoints

			local redwin = red.Value > blue.Value
			local bluewin = blue.Value > red.Value
			local tie = blue.Value == red.Value

			if redwin == true then
				game.Workspace.RedPoints.Value = 0
				game.Workspace.BluePoints.Value = 0
				game.Workspace.RedWins:FireAllClients()
				
				for i, v in pairs(game.Teams.Red:GetPlayers()) do
					v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value = v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value + 1
				end
			end

			if bluewin == true then
				game.Workspace.BlueWins:FireAllClients()
				game.Workspace.RedPoints.Value = 0
				game.Workspace.BluePoints.Value = 0
				for i, v in pairs(game.Teams.Blue:GetPlayers()) do
					v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value = v:FindFirstChild("leaderstats"):FindFirstChild("Wins").Value + 1
				end
			end

			if tie == true then
				game.Workspace.RedPoints.Value = 0
				game.Workspace.BluePoints.Value = 0
				game.Workspace.TieGame:FireAllClients()
			end
			for i, v in pairs(game.Players:GetPlayers()) do
				v.Character.HumanoidRootPart.CFrame = workspace.LobbyPart.CFrame
			end
			task.wait(60)
			
			game.Workspace.Ball.Position = Vector3.new(-2.5, 3.799, -4.5 )

			resetRed()
			resetBlue()
			game.Workspace.Ref.RefWhistle:Play()
		end
	until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
	
	task.wait() -- to prevent crashing
end

This sadly also didn’t work. I have no idea why. It seems like a simple script to me, yet I can’t figure it out