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

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

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

✓ Accepted answer

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 :)

1 comment

0

Thanks, works just as intendet :D

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