Animation only works in Studio, not in-game

Hello, DevForum. Recently, I made a “sword”, with an animation. The animation works in a studio game, but when I go into a public server with it, the animation doesn’t work. Here’s the code:

local Tool = script.Parent
local Animation = Tool.Animation

Tool.Activated:Connect(function()
	local Character = Tool.Parent
	local Humanoid = Character.Humanoid
	
	local AnimationTrack = Humanoid:LoadAnimation(Animation)
	AnimationTrack:Play()
end)

Nothing is in the output. :slight_smile:
Any help or reasons why it isn’t working?

Loading animations in humanoids is deprecated, use Animator to load animations.

So I should change it form local Humanoid = Character.Humanoid to:
local Animator = Character.Humanoid ?

If the animation isent yours it wont play in game. But if the animation was made by you and your game is in a group make sure the animation was made in the group.

1 Like
local Animator = Character.Humanoid.Animator

If this script is located in a LocalScript make sure to use WaitForChild.