Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Repeat code as long as touched?

Asked by 10 years ago

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:

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

1 answer

Log in to vote
3
Answered by 10 years ago

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

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

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

Ad

Answer this question