Wave Skip Script running while true do loop more than once

So, I have a wave skip script in a tower defense game, but it has a problem, when it the wave ends too early, that is, before 10 seconds has passed (how long it takes for the gui to pop up), it runs while true do again, while the other is still running. How would I stop this from happening?
BTW: I have a main script which sets the TimeSinceWaveStarted value to -1000, to make sure the wave skip doesnt pop up when the intermission is on.

info.CurrentWave:GetPropertyChangedSignal("Value"):Connect(function()
	info.TimeSinceWaveStarted.Value = 0
	while true do
		wait(1)
		info.TimeSinceWaveStarted.Value += 1
		if info.CurrentWave.Value == 15 then
			break
		end
		if info.TimeSinceWaveStarted.Value >= 10 then
			event:FireAllClients()
			break
		end
	end
end)
1 Like

I think CurrentWave.Value changes more often and then runs your script more often so maybe you can try

info.CurrentWave:GetPropertyChangedSignal(“Value”):Connect(function()
print(“Triggered”)
–Your Code

1 Like

yes, exactly, I just need it to stop running the previous loop and start the new one.

Maybe

local LastWave = - math.huge

info.CurrentWave:GetPropertyChangedSignal(“Value”):Connect(function()
if LastWave == CurrentWave.Value then return end
LastWave = CurrentWave.Value
–Your code
end)

1 Like

but then the wave skip wont ever run again throughout the entire match because of the return?

O but if you do

if LastWave ~= CurrentWave.Value then
LastWave = CurrentWave.Value
– Your code
end

1 Like

And local LastWave you need that outside the connections