I seem to have a problem where it will repeat the same amount of times I clicked a button, and it seems to repeat the i variable and then repeat it like (2 times of clicking the button = 2+ prints.
I want to fix this but I’m unsure what to do
My code:
local Barriers = script.Parent:WaitForChild("Barriers")
local GameStatus = script.Parent.Parent:WaitForChild("GameStatus")
local Countdown = script.Parent.Parent:WaitForChild("Countdown")
local Value = false
GameStatus.Changed:Connect(function(NewValue)
if NewValue then
Value = true
local CountDown = tonumber(Countdown.Value)
Barriers.Barrier1.CanCollide = true;
Barriers.Barrier2.CanCollide = false;
while Value ~= false do wait()
if Value ~= true then
Barriers.Barrier1.CanCollide = true;
Barriers.Barrier2.CanCollide = true;
break
end
Barriers.Barrier1.CanCollide = false
Barriers.Barrier2.CanCollide = false
for i = tonumber(CountDown), 0, -1 do wait(1)
if Value ~= true then
Barriers.Barrier1.CanCollide = true;
Barriers.Barrier2.CanCollide = true;
break
else
print(i)
end
end
Barriers.Barrier1.CanCollide = true
for i = 15, 0, -1 do wait(1)
if Value ~= true then
break
else
print(i)
end
end
Barriers.Barrier1.CanCollide = false
Barriers.Barrier2.CanCollide = false
for i = tonumber(CountDown), 0, -1 do wait(1)
if Value ~= true then
Barriers.Barrier1.CanCollide = true;
Barriers.Barrier2.CanCollide = true;
break
else
print(i)
end
end
Barriers.Barrier2.CanCollide = true
for i = 15, 0, -1 do wait(1)
if Value ~= true then
Barriers.Barrier1.CanCollide = true;
Barriers.Barrier2.CanCollide = true;
break
else
print(i)
end
end
end
else
Value = false
end
end)
I’d appreciate the help to figure out why it keeps repeating, I made sure the game resets and etc but it seems to repeat this.
They seem to be coming from the queue of the next for i loop, unsure of how I can possibly fix this though. Please let me know of anyway to fix this