How do i play a animation form a tool properly?

script.Parent.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function()
    animation = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
    animation:Play()
end)
end)

script.Parent.Unequipped:Connect(function()
    animation:Stop()
end)

I can run this script Studio and locally it will perform fine, but when I have a friend test it or I run it outside of Studio nothing happens and nothing appears in the output

1 Like

this should help with what you need! Here!

You need to use Humanoid.Animator:LoadAnimation().

1 Like

I wouldn’t use the Mouse Object to detect when the tool gets activated, there’s already an Event for Tools made for this called the Activated Event lol

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")
local Animation = Tool:WaitForChild("Animation")

local LoadAnim = Animator:LoadAnimation(Animation)

Tool.Activated:Connect(function()
    LoadAnim:Play()
end)

Tool.Unequipped:Connect(function()
    LoadAnim:Stop()
end)

Also you should define your variables ahead of time, try not to make them entirely all global

1 Like

I tried all of these and for some reason, none of them worked. Could it have something to do with the fact that I’m in team create? I’ve tried 100 different scripts and none of them work properly but also don’t print any errors in the output.

Just noticed this sentence:

If it’s a LocalScript, the changes would only be made to your side & your friend won’t be able to see the animation being played (Same thing goes & vice versa)

You can change it to a ServerScript instead with referencing the variables like so, and it should play globally for everyone to see:

local Tool = script.Parent
local Animation = Tool:WaitForChild("Animation")
local Character, Animator, LoadAnim

Tool.Activated:Connect(function()
    Character = Tool.Parent
    Animator = Character:WaitForChild("Humanoid"):WaitForChild("Animator")

    LoadAnim = Animator:LoadAnimation(Animation)
    LoadAnim:Play()
end)

Tool.Unequipped:Connect(function()
    LoadAnim:Stop()
end)

You do own the animations right? Stupid question but I thought I would ask.

I do indeed however im working within a friends game, but when I let him make the animations they only worked for him