Why does this code not work anymore?

Hello, I made a map system about a year ago now and it worked find until now?

this script is supposed to change the timer value but it dosent work?

local timer = 240

while true do
	wait(1)
	timer = timer - 1
	script.Parent.TextButton.Text = "Next Obby In "..timer.. " "
	if timer == 0 then
		timer = 240
	end
end

and this code is supposed to change witch map is currently showing?

while true do
	local tower1 = game.ReplicatedStorage.Towers.Tower1:Clone()
	tower1.Parent = game.Workspace
	wait(240)
	tower1:Destroy()
	local tower2 = game.ReplicatedStorage.Towers.Tower2:Clone()
	tower2.Parent = game.Workspace
	wait(240)
	--wait(2)
	tower2:Destroy()
	local tower3 = game.ReplicatedStorage.Towers.Tower3:Clone()
	tower3.Parent = game.Workspace
	wait(240)
	--wait(2)
	tower3:Destroy()
end

can someone tell me what has updated and no longer works in these?

2 Likes

First Script you used a timer variable but in the 2nd one you use a wait why not do the same thing you did in the first script to the 2nd one and there’s no syntax in ur script that’s outdated.

And also even if the script does work… the timer variable in the first script may start running 0.5 - 1 seconds before the wait runs which may cause a slight delay

the timer is not working at all? any reason its getting stuck you think?

are they both in the same script?

ok so umm Did you add a IntValue?

Primary reason is that you are checking if the timer is 0 or not.

if timer == 0 then
	timer = 240
end

Why is that?
Well, you cannot reliably believe in numbers to be exact. Reliability might be an issue in numbers where they tend to bump into floating-point errors. Use <= operator instead.

Also instead of while true do you could you just say while wait(1) do