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

Repeat code as long as touched?

Is there a way to make it so as long as the player is touching an object, every 2 seconds he loses health.

Sort of like:

while script.Parent.Touched do
   print("Hes touching it. ;-)")
end

1 answer

✓ Accepted answer

Erm, just an experiment. Try this in your desired part:

script.Parent.Touched:connect(function (hit)
	if not hit.Parent:FindFirstChild("Humanoid") then return end
	repeat
	hit.Parent.Humanoid:TakeDamage(10)
	wait(2)
	until script.Parent.TouchEnded
end)

Don't downvote on this, it's purely experimental for me too. If it worked, leave a +1

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