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 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

✓ Accepted answer

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?

2 comments

0

Activated is an RBXScriptSignal, not a boolean value. Use Connect() on it to connect it to a function.

0

script.Parent.Activated:Connect(function() --CODE GOES HERE end)

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

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