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.

local part = workspace.BRICK
local touch = false -- Debounce

part.Touched:Connect(function(hit)
    touch = true
    while touch do
        wait(.5) -- Delay
        -- Code here
        part.TouchEnded:Connect(function()
            touch = false
        end)
    end
end)

If this helped you please mark as answered :)

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

Answer this question