Why is wait() not working (Please help)

Hi, I made a timer script for a soccer game, but sadly wait(10) is not working.

Script:

while true do
	
	minutesvalue.Value = minutes
	secondsvalue.Value = seconds

	repeat
		if secondsvalue.Value <= 0 then
			minutesvalue.Value = minutesvalue.Value - 1
			secondsvalue.Value = 59
		else
			secondsvalue.Value = secondsvalue.Value - 1
		end
		
		workspace.BlueServer.OnServerEvent:Connect(function()
			if paused == false then
				paused = true
				print("blueserver")
				wait(10)
				paused = false
			else
				return
			end
		end)
		
		workspace.RedServer.OnServerEvent:Connect(function()
			if paused == false then
				paused = true
				print("redserver")
				wait(10)
				paused = false
			else
				return
			end
		end)
		
		wait(1)
		
		if secondsvalue.Value == 1 and minutesvalue.Value == 0 then
			if timeextra == false then
				local extratime = math.random(0, 5)

				extratimeevent:FireAllClients(extratime)
				wait(1)
				secondsvalue.Value = 0
				minutesvalue.Value = extratime
				timeextra = true
			end
		end
		
		if secondsvalue.Value <= 0 and minutesvalue.Value <= 0 then
			timeextra = false
			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
				workspace.arePlayersInMap.Value = false
			end
			wait(60)
			
			game.Workspace.Ball.Position = Vector3.new(-2.5, 3.799, -4.5 )

			resetRed()
			resetBlue()
			workspace.arePlayersInMap.Value = true
			game.Workspace.Ref.RefWhistle:Play()
		end
	until secondsvalue.Value <= 0 and minutesvalue.Value <= 0
	task.wait()
end

Any errors?
Is ‘blueserver’ or ‘redserver’ being printed? If not then the function isn’t being called.

Maybe do

repeat wait() until pause == false

So it waits for the game to unpause?

Also you should move

^^ this code above the while true do loop.

1 Like

It does print, yet it does not wait.

However, the wait(1) function above does run. (used for counting down every second)

It works, thank you very much.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.