Why doesn't my animation play?

My animation doesn’t play and I’m using a local script. This is the script:

script.Parent.MouseButton1Click:Connect(function()
	local Anim =  game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Animation)
	Anim:Play()
	print("playedddd")
end)

There were no errors and it printed the ‘playedddd’ text. I tried this on another local script, it works but I’m not sure why suddenly it doesn’t work.

See below for the hierarchy, thanks.

image

1 Like

Humanoid:LoadAnimation() has been replaced by Animator:LoadAnimation()

script.Parent.MouseButton1Click:Connect(function()
    local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
    local Anim = Humanoid:WaitForChild("Animator"):LoadAnimation(script.Animation)
    Anim:Play()
    print("playedddd")
end)
1 Like

So I tried to do that, I used the code from the developer website article but what happened is the ‘got here’ was printed but ‘ran’ wasn’t printed. No errors either. It still doesn’t work.

script.Parent.MouseButton1Click:Connect(function()
--[[	local Anim =  game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Animation)
	Anim:Play()
	print("playedddd")--]]
	print"got here"

	local character = game.Players.LocalPlayer.Character
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		-- need to use animation object for server access
		local animator = humanoid:FindFirstChildOfClass("Animator")
		if animator then
			local animationTrack = animator:LoadAnimation(script.Animation)
			animationTrack:Play()
			return animationTrack
		end
	end
	print"ran"
end)
1 Like

I think it’s because Character, Humanoid, or Animator hasn’t loaded yet.
Use this:

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

script.Parent.MouseButton1Click:Connect(function()
    print"got here"
    animator:LoadAnimation(script.Animation):Play()
    print"ran"
end)
1 Like

Strange it still won’t work, no idea why and no errors. It printed both prints tho.

Maybe the animation is the problem, please check it and republish it, if it doesn’t work, try placing it in another asset.

Sorry I forgot to emphasise that it did work before on an empty baseplate when I was making it.

If it doesn’t work, would you like to find the character in your workspace?

local Player = game.Players.LocalPlayer
local Char = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Char:WaitForChild("Humanoid")
local Animation = script:WaitForChild("Animation")
script.Parent.MouseButton1Click:Connect(function()
	local Anim = Humanoid:LoadAnimation(Animation)
	Anim:Play()
end)

I tested it. If this really doesn’t work, I think there’s a problem with animation.
And make sure the animation belongs to your account.
Thank you.

The animation does belong to my account and it has worked before, like I said, but in a different game (in fact it was just empty baseplate). That’s the code I used as well.

The owner of your game and the owner of the animation should be the same. Otherwise, the animation will not work.

Examples of incorrect methods:

  1. publishing animations to Jiwonz’s account without putting animations in the group Game Party Studio game. => does not work
  2. developer published animation to developer’s account and Jiwonz used it for his game => does not work

Example of the correct method:

  1. He makes his own animations and publishes them to his account and uses them. => work
  2. After being created by the developer, use animation after publishing to the group. => work

Edit: Added more things

What can I say, you’re right!! I didn’t even know about the ownership part and didn’t notice I uploaded it as my own when instead should’ve uploaded it to the group. Thanks!

1 Like