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 + 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

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.

1 Like

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