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

Damage Can Be Spammed, and I Can't Figure Out Why?

Asked by 4 years ago

So basically whenever you hit the player you can keep on clicking the weapon which deals damage, I want it so you can only deal the damage 1 time if the weapon is activated?

Any Ideas Why My Script Is Doing This?

server script in Tool

Av = script.Parent.DamageValue.Value --Attack Value 
local CanDamage = script.Parent.CanDamage
tool = script.Parent

function tagHumanoid(humanoid,killer)

    if humanoid and killer then

        local tag = Instance.new("ObjectValue")
        tag.Name = "Killer"
        tag.Value = killer
        tag.Parent = humanoid
    end

end

script.Parent.Activated:Connect(function()

    CanDamage.Value = true

    if script.Parent.Handle.Touched then

        script.Parent.Handle.Touched:Connect(function(p)

    local plr = game.Players:GetPlayerFromCharacter(tool.Parent)

    if script.Parent.CanDamage.Value == true and p.Parent:FindFirstChild("Humanoid") then

    script.Parent.CanDamage.Value = false

    local humanoid = p.Parent:FindFirstChild("Humanoid")

    humanoid:TakeDamage(Av)

    tagHumanoid(humanoid, plr)

    wait(.2)

    script.Parent.CanDamage.Value = true

    if p.Parent.Humanoid.Health < 1 then
        print("Player Has Died")
    end

    end
        end)
        end
end)
0
There is only 1/5th of a second between each time being able to fire MrLonely1221 701 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

What MrLonely1221 said is right. You state


wait(.2) script.Parent.CanDamage.Value = true

after setting CanDamage.Value to false, thus you can deal damage every 0.2 seconds. To fix this, just never set CanDamage.Value to true. Only do it in the beginning of your function, like you have.

Further more your indenting scares me. http://blackmiaool.com/lua-beautify/ can help you learn how to indent and make your code 10x prettier.

0
Even though I removed the part where the Value turns true, I'm still able to spam the weapon and deal the damage? Jomeliter 55 — 4y
0
Do you want the weapon to be able to deal damage every time you equip it or just once overall? GriffthouBiff 147 — 4y
0
Another thing you can do is to increase the wait time. killerbrenden 1537 — 4y
0
I want it to deal damage every time you equip it, but only once every click Jomeliter 55 — 4y
0
I've tried changing wait time? Still allows you to do a lot of damage by spamming Jomeliter 55 — 4y
Ad

Answer this question