Animation plays in studio, not in game

So I’ve been working on shield holding animation that is supposed to play while in holding the tool, however, it only works in studio test mode.
STUDIO TEST MODE POV:
image
GAME POV:
image

The localscript I used is:

local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid")
local anim = h:LoadAnimation(script.Parent:WaitForChild("Animation"))

local tool = script.Parent

tool.Equipped:Connect(function()
	anim.Looped = true
	anim:Play()
end)
tool.Unequipped:Connect(function()
	anim.Looped = false
	anim:Stop()
end)

If anyone could help me, I would be very grateful as I have no explanation for this.

2 Likes

The group/game owner needs to have the animation in their inventory or the game server will refuse to load it.

1 Like

I mean, didn’t he say he made the animation? Meaning its probably already in his inventory.

Is this a group game or a personal game? If it’s a group game make sure the animations are uploaded to the group, not your personal account.

Other than that there’s not really much that would be causing your animation not to work.

Make sure the animation is created by the game creator. If the creator is a group, create the animation from the group, but if you made it, make sure you created the animation on your profile.

Well I am the group owner and the creator of the audio. As such, I don’t really know where is the problem.

Well I exported the animation as group creation and yet it still does not work.

Your issue is a particular pitfall with Roblox animation replication, due to this line of code:

local anim = h:LoadAnimation(script.Parent:WaitForChild("Animation"))

The problem is, that if you call Humanoid:LoadAnimation from a LocalScript and the Humanoid does not already have an Animator instance as a child, LoadAnimation will create one. But… an Animator created on the client replicates nothing to or from the server. The solution is to always create the Animator on the server, and have the client wait for it with WaitForChild(). You can do this either by calling LoadAnimation from a server script when the character spawns, or by simply using Instance.new(“Animator”) on the server at character load time, and parenting it to the Humanoid.

The way to avoid the pitfall is to always make sure LocalScripts are waiting for a server-created Animator under the Humanoid before making any LoadAnimation() calls.