How do I end a loop?

I’m trying to make the bar deplete and end at zero but it just goes into the negatives.


Heres my script:

local hyperActivate = game:GetService("ReplicatedStorage"):WaitForChild("HyperActivate")
local evasiveActivate = game:GetService("ReplicatedStorage"):WaitForChild("EvasiveActivate")

hyperActivate.OnServerEvent:Connect(function(plr)
	plr:FindFirstChild("Hyper"):FindFirstChild("HyperActive").Value = true
	while wait(.01) do
		repeat task.wait(1)
			plr:FindFirstChild("Hyper").Value -= 1
		until plr:FindFirstChild("Hyper").Value == 0
	end
	plr:FindFirstChild("Hyper"):FindFirstChild("HyperActive").Value = false
end)

break

You have a loop inside of a loop. I’m pretty sure that is not what you want. You only want one loop.

1 Like

Additionally, having two loops can increase ping, which would be considered bad practice.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.