Stop a part script after touching another part

Hey Devs

I have a part with this script, how could I make it so when you touch another part this scripts stops… cause it seems to never stop until player dies… I tried adding a
h.health + 6
stops the death but it still takes health. also I can’t do reset cause I need to save the position of player

	function onTouched(hit)
	    local h = hit.Parent:findFirstChild("Humanoid")
	    while true do
	        if (h ~= nil) then
	            h.Health = h.Health - 6
	            wait(3)
	        end
	    end
	end
	 
	script.Parent.Touched:connect(onTouched)

Instead of doing a while true do loop, you could instead use a repeat wait() until loop, as this loop will run infinitely until it meets a requirement. You could detect when the player touches another part, or stops touching that part, and then stop the loop.

2 Likes

You can make it so that when it’s touched it loops through all the other scripts and disables them. Sorry if I misunderstood.