Quick scripting issue, any help appreciated!

Hello all! Just looking to see if there’s any bugs in my code I can clear here, or if it’s an issue somewhere else, all help appreciated! :grin:

  1. What do you want to achieve? Keep it simple and clear!

I’m adding a countdown and TextLabel into my tower game, and I’m currently having issues with my script, so I’m checking here if it’s just here or if there’s an issue in my script elsewhere!

  1. What is the issue? Include screenshots / videos if possible!
function countdown()
	local status = game.ReplicatedStorage.Status
	local GameLength = 60
	for i = GameLength,0,-1 do
		
		status.Value = "There is "..GameLength.." seconds left."
		
		if GameLength == 0 then
			
			plr:LoadCharacter()
			
	wait(1)
			
		end
	end
	
end

This script is supposed to count down from 60 to 0, but instead it starts the function and ends it instantly, and my TextLabel doesn’t change. I don’t know if there’s a way for when it gets to 0 that you can possibly continue the script, since my tower game script is a while true do loop, but if there is that might be the problem.

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

I did a quick skim over the developer hub, but there’s not much as I’ve seen related to my script’s base.

Any help on this topic would be amazing, thank you for reading and have a great day! :+1:

I think it is because the wait is in the if statement and not inside the for loop.
Try doing this, idk if it will work:

function countdown()
	local status = game.ReplicatedStorage.Status
	local GameLength = 60
	for i = GameLength,0,-1 do
		wait(1)
		status.Value = "There is "..GameLength.." seconds left."
		
		if GameLength == 0 then
			
			plr:LoadCharacter()
			
	wait(1)
			
		end
	end
	
end
1 Like

Right, so the timer is now working how it’s supposed to, and replacing the towers after a minute, but my TextLabel is still not updating, so I’ll put my LocalScript here which is inside the TextLabel, so if it’s something here that you could see that would be phenomenal, thank you! :grin:


script.Parent.Text = Status.Value

Status:GetPropertyChangedSignal("Value"):Connect(function()
	
	script.Parent.Text = Status.Value
	
end)

Try doing i because i represents the numeric for loop going down.

status.Value = "There is "..i.." seconds left"

Also, @SpacialEthanRB you don’t need to add a wait inside the numeric loop, as that would probably mess up the intermission system quite a bit.
@iiBobaPotato

1 Like

Yep! That fixed the issue with the timer, thanks so much! :+1:

1 Like