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 enemy script not consistently do damage to me?

I made this script and I would like to know how I can create a damage script that doesn't do mega damage such as this. It consistently ticks over and over in an instance and I can't know how to fix it. I would be happy for any help possible.

-- Damage script
local rarm = script.Parent:FindFirstChild("Right Arm")
local larm = script.Parent:FindFirstChild("Left Arm")

function dmg(hit)
	if hit.Parent ~= nil then
		local hum = hit.Parent:findFirstChild("Humanoid")
		if hum ~= nil then
			hum.Health = hum.Health -2
		end
	end
end

rarm.Touched:connect(dmg)
larm.Touched:connect(dmg)

1 answer

✓ Accepted answer

Maybe using a debounce could solve your problem.

Create the variable:

local debounce = false

Then put in your function:

if debounce == false then
	debounce = true
	--The rest of your code.
end

When you want your function to work again, just set the debounce to false again with:

debounce = false

I hope that this could help you.

2 comments

0

Me: I see this question I think debounce should do it, Clicks on question.. the moment I realized the question is already answered.

0

Doesn't work I'm trying to manipulate this in some sort of way that works, it might just be that my brain is backwards right now.

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