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

How do i make a loop that repeats a certain action while the character is touching a certain part?

Asked by
Echtic 128
5 years ago

So i need the loop to keep damaging the player every let's say .5 seconds while he is touching a certain part, and when he stops for it to stop as well. I am not asking for someone to make the whole script for me, i need someone to help me make it. I'd really appreciate if someone told me what to do and maybe linked me the developer wiki article connected to that.

1 answer

Log in to vote
1
Answered by 5 years ago

You could do something like this.

01local part = workspace.BRICK
02local touch = false -- Debounce
03 
04part.Touched:Connect(function(hit)
05    touch = true
06    while touch do
07        wait(.5) -- Delay
08        -- Code here
09        part.TouchEnded:Connect(function()
10            touch = false
11        end)
12    end
13end)

If this helped you please mark as answered :)

0
Thanks, works just as intendet :D Echtic 128 — 5y
Ad

Answer this question