While loop is not breaking

Have tried multiple variants on how to break while loop, however they didn’t work. Wait(x) still should stay so it regulations the time until next value decrease, however, if the limb health goes greater than bleeding point it should break the loop.

head.Changed:Connect(function()
	local lightbleeding = head.Value <= 80 

	if lightbleeding then   
		player.PlayerGui.MainGui.Frame.Health.ImageTransparency = 0
		BloodScreen:Play()
		print("1")
		while true do
			if lightbleeding then
				blood.Value = blood.Value - 1
				wait(1)
				else
				break
			end
		end
	else 
		print("5")
		player.PlayerGui.MainGui.Frame.Health.ImageTransparency = 1
		print("6")
	end
head.Changed:Connect(function()
	local lightbleeding = head.Value <= 80

	if lightbleeding then   
		player.PlayerGui.MainGui.Frame.Health.ImageTransparency = 0
		BloodScreen:Play()
		print("1")
		while task.wait(1) do
			if lightbleeding then
				blood.Value -= 1
			else
				break
			end
		end
	else 
		print("5")
		player.PlayerGui.MainGui.Frame.Health.ImageTransparency = 1
		print("6")
	end

fixed a bit of your code

It still doesnt break the loop and even more, if value being changed more than once in range of below and or 80 it makes a double loop.

Hi, here is a sample on how you would create & break a loop.

local Looping = false
local lightbleeding
Head.Changed:Connect(function()
	lightbleeding = head.Value <= 80 
	if lightbleeding then
		player.PlayerGui.MainGui.Frame.Health.ImageTransparency = 0
		BloodScreen:Play()
		if not Looping then
			Looping = true
			while lightbleeding and blood.value > 0 do
				blood.value -= 1
				task.wait(1)
			end
			Looping = false
		end
	else
		player.PlayerGui.MainGui.Frame.Health.ImageTransparency = 1
	end
end)
1 Like

Whenever and however I wouldn’t test it at studio it keeps running blood.value -=1.
upd: nvm solved the issue

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