Countdown doesn't work properly

Hey, so i want to Debugg my Countdown script im working on…

im having issue with the Text that gets diplayed it works one time but after that if i press my button again the Countdown displays and quickly changes again to the countdown and again and again, again… you get it right?

so its very important that if i click the button again the Countdown works normally and if the button is not clicked and the Countdown is over the script should wait until the button is clicked and repeats.

local roundLength = 30
local intermissionLength = 0
local inRound = game.ReplicatedStorage.inRound
local Status = game.ReplicatedStorage.Status	



local function roundCountdown()
		while wait() do
			for i = roundLength, 1, -1 do
				inRound.Value = false
				wait(1)
			Status.Value = "Game: "..i.." seconds left!"
            print(Status.Value)			
			    end
			for i = intermissionLength, 0, -0 do
				inRound.Value = false
				wait(1)
			Status.Value = "intermission: Press the Button to Start the Game!"
		   end
		end
     end

local onCooldown = false

wait(game.Workspace.General.Button.ClickDetector.MouseClick:Connect(function(click)
	

	    if onCooldown == false then

		onCooldown = true
	
		spawn(roundCountdown)
		
		
		task.delay(30, function()

	    onCooldown = false
		end)
	end
end))

so if you could fix the little thing im having issues with i would learn something from it and i can work on other parts of my game.

2 Likes

try this

local roundLength = 30
local intermissionLength = 0
local inRound = game.ReplicatedStorage:WaitForChild("inRound")
local Status = game.ReplicatedStorage:WaitForChild("Status")	
local onCooldown = false
local function roundCountdown()
          for i = roundLength, 1, -1 do
			inRound.Value = false
			task.wait(1)
			Status.Value = "Game: "..i.." seconds left!"
            print(Status.Value)			
			  end
			for i = intermissionLength, 0, -0 do
			inRound.Value = false
			task.wait(1)
			Status.Value = "intermission: Press the Button to Start the Game!"
    end
end

game.Workspace.General.Button.ClickDetector.MouseClick:Connect(function(click)
	    if onCooldown == false then
		onCooldown = true
		spawn(roundCountdown)
		task.delay(30, function()
	    onCooldown = false
		end)
	end
end)
1 Like

this gives me the same Problem.

it works just fine for me, is this code in a local script or a server script

the Script is in the SeverScriptService so its an server script.

I cannot find the problem it works just fine for me what’s the code for text

Yeah for round one but after that it displays the Problem.

what’s the code for displaying text?

local Status = game.ReplicatedStorage.Status
local CountdownDisplay = script.Parent.CountdownDisplay

Status.Changed:Connect(function()
	CountdownDisplay.Text = Status.Value
end)

it works fine for me

here’s a video

robloxapp-20220618-1257460.wmv (239.8 KB)

Could you upload an diffrent type of file? i recommend MP4.

Uhm i wanted you to upload a MP4 Video because i dont want to Download stuff.

I don’t know how to upload a MP4 Video I used the roblox recorder

here’s the code that worked for me

local roundLength = 30
local intermissionLength = 0
local inRound = game.ReplicatedStorage:WaitForChild("inRound")
local Status = game.ReplicatedStorage:WaitForChild("Status")
local Test = false	
local onCooldown = false

local function Intermission()
	inRound.Value = false
	Status.Value = "intermission: Press the Button to Start the Game!"
end

local function roundCountdown()
     			for i = roundLength, 0, -1 do
				inRound.Value = false
			task.wait(1)
			Status.Value = "Game: "..i.." seconds left!"
            if i < 1 then
            print(Status.Value)		
          Intermission()	
         end
    end
end
game.Workspace.General.Button.ClickDetector.MouseClick:Connect(function(click)
	    if onCooldown == false then
		onCooldown = true
		spawn(roundCountdown)
		task.delay(30, function()
	    onCooldown = false
		end)
	end
end)

Capture

now it works for some reason anyway thank you so much!