I have a damage script below, where if you hit a part, you take damage onTouched. If you stand still on the part, you will only take damage once until you move slightly. How do I make it so that you take damage every second while standing on the part stationary?

local debounce = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and debounce == false then
		debounce = true
		hit.Parent.Humanoid:TakeDamage(75)
		wait(1)
		debounce = false
	end
end)

4 comments

0

I tried using .TouchEnded() but it worked very clumsy. I would try defining a Region3 covering up your damaging part and slightly above it and then run an infinite loop that checks if there's a character in contact with said region3 to damage them. A complicated and memory hungry solution, but pretty effective I believe.

0

How would I check if there is a player? I understand :GetTouchingParts(), but how do I confirm it's a humanoid?

0

if hit.Parent:FindFirstChild("Humanoid") then

0

touched should keep firing, i dont understand what ur asking