Loop doesnt break when I dont touch the part anymore

  1. What do you want to achieve?

I want this script to do so when a player is touching the Fire, the player will take damage until the player isnt touching the Fire anymore.

  1. What is the issue?

The player still takes damage after not touching the Fire anymore

  1. What solutions have you tried so far?

I have tried a lot of combinations, but none of them worked

local Fire = script.Parent

Fire.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and game.Players:FindFirstChild(hit.Parent.Name) then
		while true do
			print("Burning")
			hit.Parent.Humanoid.Health += -1
			wait(0.1)
			if Fire.TouchEnded == true then
				break
			end
		end

	end
end)


TouchEnded, like Touched, is an event that roblox fires whenever the player stops touching a BasePart. You need to treat it just like you treated the .Touched event, using the :Connect() method. I would have the .TouchEnded event change a boolean variable to true, and then when that boolean variable is true break out of your while loop.

1 Like

You know the while true do is not worth it since what you should use is takedamage and also I’m going to pass you a script
Please wait
I’m going to open the studio

Thank you, I got it to work very well

I fixed it, you dont have to use any more time on this : )

ok go just in case


local zona = script.Parent

zona.Touched:Connect(function(hit)	

	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Parent.Humanoid:TakeDamage(0.1)
	end
end)



1 Like

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