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 my damage script not spam damage when I touch it?

My damage script keeps on spamming damage every time I touch it. What do I do?

function touch(hit)
	hit.Parent:FindFirstChild("Humanoid").Health = hit.Parent:FindFirstChild("Humanoid").Health -10
	
end

script.Parent.Touched:connect(touch)

Thanks!

1 comment

0

use a for loop

2 answers

✓ Accepted answer
local debounce = true

function touch(hit)
	if hit.Parent:FindFirstChild("Humanoid") then -- prevent errors if hit isnt a char
		if debounce == true then
			hit.Parent.Humanoid:TakeDamage(10)
			debounce = false
			delay(1, function() debounce = true end) -- this will run 1 second latter
		end
	end
end

script.Parent.Touched:connect(touch)


2 comments

0

you made a mistake its if debounce == true

0

thanks fixed

The problem you made is there is no block for when you don't want it spam damaging. Try using a variable as a block like this:

local block = true

function touch(hit)
if hit.Parent.Humanoid and block == true then
hit.Parent.Humanoid:TakeDamage(10)
end)

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