Animation doesn't play

There are no errors, and this is on the server. The animation simply doesn’t play.

Code:

game.ReplicatedStorage.Emote.OnServerEvent:Connect(function(player, animid, looped)
	local humanoid = player.Character.Humanoid
	
	local Anim = Instance.new("Animation")
	Anim.AnimationId = "rbxassetid://" .. animid
	
	if humanoid:IsA("Humanoid") then
		print("Received hum")
		local animator = humanoid:WaitForChild("Animator")
		
		if animator then
			print("Received animator")
			local animationTrack = animator:LoadAnimation(Anim)
			animationTrack.Looped = looped
			animationTrack:Play()
			
			return animationTrack
		end
	end
end)

Output:
image

1 Like

Is this inside a script? If so are you trying to play animations on a NPC or a player? If you want do this on a player you’ll need a local script

A little more than halfway down the page under “Playing Animations Directly”

1 Like

I’ve had this issue once. Are you using the animation on a group game? If you are the animation should be uploaded by the group, or else it wont work.

1 Like

No, it’s a personal game.

This might be a roblox bug, maybe your animation is not loading, or your animation is not working

So I can see in your output that it is inside a script, so if this is an animation your trying to play on yourself it should be placed inside a local script`

1 Like

Yeah, thanks I can’t believe I forgot that anims have to be on the client lol

Ok, there’s another problem. I am running this on the client but it still will not play the animation.
Code:

-- yes i do call the function, and ID and looped are valid
local function playAnim(ID, looped)
	local character = game.Players.LocalPlayer.Character
	
	if not character or not character.Parent then
		print("not char")
		character = game.Players.LocalPlayer.CharacterAdded:Wait()
	end
	
	local humanoid = character:WaitForChild("Humanoid")
	local animator = humanoid:WaitForChild("Animator")
	
	local Animation = Instance.new("Animation")
	Animation.AnimationId = "rbxassetid://" .. ID
	
	local AnimationTrack = animator:LoadAnimation(Animation)
	AnimationTrack.Looped = looped
	
	if AnimationTrack then
		print("got anim")
		AnimationTrack:Play()
	end
end

Output:
image
(i clicked twice)

Did you create the animation yourself? Or did someone else make it for you, like in Team Create, and their the owner while you’re trying to script it? The animations only play for the owner of the place (Inside studio) if the animations are owned by the place owner.

The animations in question are Roblox-made. I am the only one in studio, TC isn’t enabled, and I am the place owner.

I would probably make a quick animation, something like just moving the arm up and down, then export that and use that ID to see if there is any difference

1 Like

That’s exactly what I am doing rn lol

1 Like

Yup, my animation works but the Roblox-made do not!

Try change line 5 to:

Anim.AnimationId = "http://www.roblox.com/Asset?ID=" .. animid

I’ve tried to loading an animation using “rbxassetid://” sometimes and it hasnt worked.

ALSO heres a few modifcations I’ve made which i’m not sure if it will work but you can try.

game.ReplicatedStorage.Emote.OnServerEvent:Connect(function(player, animid, looped)
	local humanoid = player.Character.Humanoid

	local Anim = Instance.new("Animation")
	Anim.AnimationId = "http://www.roblox.com/Asset?ID=" .. animid

	if humanoid:IsA("Humanoid") then
		local animator = humanoid:WaitForChild("Animator")

		if animator then
			local animationTrack = humanoid:LoadAnimation(Anim)
			animationTrack.Looped = looped
			animationTrack:Play()

			return animationTrack
		end
	end
end)
1 Like