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

Sword Does Damage Without Being Clicked?

Asked by 4 years ago

The sword does damage without being clicked? It does damage when it's touched not when it's clicked, I can't seem to find a way to fix this.

The Damage Script For My Weapon

Av = 15 --Attack Value

tool = script.Parent

function tagHumanoid(humanoid,killer)

    if humanoid and killer then

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

end

script.Parent.Handle.blade.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(1)

    script.Parent.CanDamage.Value = true

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

    end

end)

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I tried this

Av = 15 --Attack Value

tool = script.Parent

function tagHumanoid(humanoid,killer)

    if humanoid and killer then

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

end

if script.Parent.Activated == true then
    script.Parent.Handle.blade.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(1)

        script.Parent.CanDamage.Value = true

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

        end
    end)
end

But now my weapon doesn't do damage?

0
Activated is an RBXScriptSignal, not a boolean value. Use Connect() on it to connect it to a function. DeceptiveCaster 3761 — 4y
0
script.Parent.Activated:Connect(function() --CODE GOES HERE end) royaltoe 5144 — 4y
Ad
Log in to vote
0
Answered by
haba_nero 386 Moderation Voter
4 years ago

Try using tool.Activated in your script. Activated means that it has been clicked. Hope this helps!

Answer this question