Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make my enemy script not consistently do damage to me?

Asked by
VVTF_RU 18
3 years ago

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

Log in to vote
0
Answered by
alefa03 15
3 years ago

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.

0
Me: I see this question I think debounce should do it, *Clicks on question*.. the moment I realized the question is already answered. MAD_DENISDAILY2 137 — 3y
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. VVTF_RU 18 — 3y
Ad

Answer this question