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:

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

1 answer

Log in to vote
3
Answered by 10 years ago

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

Ad

Answer this question