Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Sword Does Damage Without Being Clicked?

The sword does damage without being clicked?

It does damage when it's touched

I have no idea how 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)

1 answer

✓ Accepted answer

You're using a .Touched function on the blade. This means that the function will continue regardless if the player has clicked at all. You should consider only running the function for when the player has clicked, maybe an "if then" statement?

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