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

How do I make it so that the tool doesn't play the animation upon equipping it?

So you see, I have a sword that plays a custom animation whenever you click the mouse button.

But the problem i'm having is that it also plays the animation upon equipping the sword. How do I fix this?

local tool = script.Parent
 
local function onEquip()

end
 
local function onUnequip()
 
end
 
local function onActivate()
 local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local anim=Instance.new("Animation")
    anim.Name = "Drawanim"
    anim.AnimationId = 'http://www.roblox.com/asset/?id=348140986'
    anim.Parent = workspace

script.Parent.Equipped:connect(function (idk)
    local playanim = Humanoid:LoadAnimation(anim)
    playanim:Play()
end)

end
 
local function onDeactivate()
 
end
 
tool.Equipped:connect(onEquip)
tool.Unequipped:connect(onUnequip)
tool.Activated:connect(onActivate)
tool.Deactivated:connect(onDeactivate)

1 answer

✓ Accepted answer

Just omit the Equipped event on line 18. The Equipped event triggers every time the player equips a tool.

It should look like this:

local tool = script.Parent

local function onEquip()

end

local function onUnequip()

end

local function onActivate()
 local Humanoid = game.Players.LocalPlayer.Character.Humanoid
local anim=Instance.new("Animation")
    anim.Name = "Drawanim"
    anim.AnimationId = 'http://www.roblox.com/asset/?id=348140986'
    anim.Parent = workspace

--[[ script.Parent.Equipped:connect(function (idk)
    local playanim = Humanoid:LoadAnimation(anim)
    playanim:Play()
end) ]] --remove me

end

local function onDeactivate()

end

tool.Equipped:connect(onEquip)
tool.Unequipped:connect(onUnequip)
tool.Activated:connect(onActivate)
tool.Deactivated:connect(onDeactivate)

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