Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

(SOLVED) Why does the repeat in this script goes twice as fast after activating it a second time?

I have a script for a progress bar. The script is supposed to add 0.1 to the seconds total every 0.1 seconds up until 30 seconds. The seconds value is used to change the size of a progress bar on screen. The first time it is activated, this works perfectly. The progress bar goes up until it fills. Activating it again is supposed to reset it to zero seconds and fill up again. It does this, but it goes twice as fast as before. This makes it take 15 seconds to fill up instead of 30. Activating a third time makes it go even faster and so on. Here is the code I used.

local gui = script.Parent
local event = game.ReplicatedStorage.WallTime -- event that activates script
local frame = gui.Frame
local frame2 = frame.Frame
local seconds = 0
local ready = game.ReplicatedStorage.Ready -- event that is activated after progress bar fills

event.Event:Connect(function()
	seconds = 0
	repeat
		wait(0.1)
		seconds = (seconds + 0.1)
	until
		seconds == 30
end)
event.Event:Connect(function()
	frame2.Size = UDim2.new(0, 0, 1, 0)
	repeat
		frame2.Size = UDim2.new(seconds/30, 0, 1, 0)
		wait()
	until
	frame2.Size == UDim2.new(1, 0, 1, 0)
	
		ready:Fire()
end)

1 answer

I fixed it, this is the script I used

local gui = script.Parent
local event = game.ReplicatedStorage.WallTime
local frame = gui.Frame
local frame2 = frame.Frame
local seconds = 0
local ready = game.ReplicatedStorage.Ready


event.Event:Connect(function()
	seconds = 0
	frame2.Size = UDim2.new(0, 0, 1, 0)
end)

event.Event:Connect(function()
	seconds = 0
	while seconds < 30 do
		wait(0.1)
		seconds = (seconds + 0.1)
	end
end)
event.Event:Connect(function()
	frame2.Size = UDim2.new(0, 0, 1, 0)
	repeat
		frame2.Size = UDim2.new(seconds/30, 0, 1, 0)
		wait()
	until
	frame2.Size == UDim2.new(1, 0, 1, 0)
	
		ready:Fire()
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.