Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Touch function repeating, even if not touching?[Unanswered]

I made this script, it makes an fire instance on the part that touched it, and it kinda works! It does that and all, unfortunately it keeps making fire instances until the player is dead!!! How can I fix this? I know the problem is the "While - do" but I use that to make sure that it is a player (not just a random brick)! Here is my script

function onTouched(hit)
	while hit.Parent.Humanoid do
		wait(0.000001)
		
			if script.CanSpreadFire.Value == 1 then				
				wait(0.000001)
				script.CanSpreadFire.Value = 0				
				local fire = Instance.new("Fire")
				fire.Parent = hit
				fire.Color = Color3.new(77,175,236)
				fire.Heat = 9
				fire.Size = 2				
				local burn = script.Burn:clone()
				burn.Parent = fire
				hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 5
				wait(1)
				script.CanSpreadFire.Value = 1
			end
			
		
	end
	
end

script.Parent.Touched:connect(onTouched)

Please help!!! Thank you!!!

1 answer

✓ Accepted answer

You're using a while loop after the part is touched, which means whatever is inside it will run repeatedly. You mean to use a conditional if then statement; if hit.Parent:FindFirstChild("Humanoid")then

This discussion is preserved as it was. New answers, comments, and votes are closed.