Animation not playing?

Hey guys, I was wondering why my animation is not playing. I followed the dev hub tutorial and it seems to not work.

-- create a idle animation
local Players = game:GetService("Players")

local function onCharacterAdded(character)
	local humanoid = character:WaitForChild("Humanoid")
	
	for _, playingTracks in pairs(humanoid:GetPlayinganimationTracks()) do
		playingTracks:stop(0)
		
	end
	
	local animateScript = character:WaitForchild("Animate")
	
	animateScript.idle.Animation1.AnimationId = "rbxassetid://3907655156"
	-- assign weight 5 to anim 1
	animateScript.idle.Animation1.Weight.Value = 5
	
	animateScript.idle.Animation2.AnimationId = "rbxassetid://3907655156"
	-- assign weight 5 to anim 2
	animateScript.idle.Animation2.Weight.Value = 5
end

local function onPlayerAdded(player)
	if player.Character then
		onCharacterAdded(player.Character)
	end
	player.CharacterAdded:Connect(onCharacterAdded())
end

Players.PlayerAdded:Connect(onPlayerAdded)

My character just does the normal roblox idle animation.

5 Likes

There are multiple issues.

Nitpick 1

should be

humanoid:GetPlayingAnimationTracks()
Nitpick 2

should be

playingTracks:Stop()
Nitpick 3

should be

player.CharacterAdded:Connect(onCharacterAdded()) 

It turns out that you weren’t trying to play an animation.

Redacted

The biggest issue is that you never loaded the animation and played it.

Here’s how you do it:

...

local LoadedAnimation = Humanoid:LoadAnimation(AnimationName)
LoadedAnimation:Play()

This is just an example, so just use this as loose guidelines for you follow. Don’t copy it verbatim.

Spoonfeeding
local function onCharacterAdded()
	 for _, playingTracks in pairs(humanoid:GetPlayinganimationTracks()) do
		playingTracks:stop(0)
		
	end
	
	local animateScript = character:WaitForChild("Animate")
	
	animateScript.idle.Animation1.AnimationId = "rbxassetid://3907655156"
	-- assign weight 5 to anim 1
	animateScript.idle.Animation1.Weight.Value = 5
	
	animateScript.idle.Animation2.AnimationId = "rbxassetid://3907655156"
	-- assign weight 5 to anim 2
	animateScript.idle.Animation2.Weight.Value = 5
end

local function onPlayerAdded(player)
	if player.Character then
		onCharacterAdded(player.Character)
	end
	 player.CharacterAdded:Connect(onCharacterAdded)
end

Players.PlayerAdded:Connect(onPlayerAdded)
11 Likes

Yes, I agree with @mobyboyy
Make sure that the animations are uploaded onto your account, or a group you own, otherwise the animations will not load, also if the issue persists send a screenshot of f9 for any errors.

And yes that animation won’t play because you haven’t actually used :Play(), the rest is completely spot on by @mobyboyy

3 Likes

Ok so I am getting this.

EDIT: forgot the script is in the serverscriptservice and not local. Would I have to put this in a local script?

1 Like

The script does not have to be a LocalScript it can run inside of a server-sided script. I have cleaned up your code for you, but you need to make sure that you capitalize things that are supposed to be capitalized.

For example, waitforchild() will not work, you must type it as WaitForChild()

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		local Humanoid = Character:WaitForChild("Humanoid")
		for _,playingTracks in pairs(Humanoid:GetPlayingAnimationTracks()) do
			playingTracks:Stop()
		end
		local animateScript = Character:WaitForChild("Animate")
		animateScript.idle.Animation1.AnimationId = "rbxassetid://3907655156"
		animateScript.idle.Animation1.Weight.Value = 5		
		animateScript.idle.Animation2.AnimationId = "rbxassetid://3907655156"
		animateScript.idle.Animation2.Weight.Value = 5
	end)
end)
1 Like

I have tried that before and it does not work.

1 Like

Did you create these animations? Because if you are not the owner you will not be able to use them.

2 Likes

yes I did, the game is in my group creations, does it have to be specifically under group creations for it to work? or can it be my own animations not made under the group?

1 Like

If it is a group game, the animations have to be owned by the group.
If it is a game created by you the animations have to be owned by you.

3 Likes

Ah ok, its my own group game but I am using my own animations. So that is why it’s probably not working.

So i had recently bought an a sword animation, It came with a sword, 2 sword swings animations, and an idle. I bought it for 700R. But it turns out that he had animation Id’s but the animations for which the Id’s come from are not in the file they game me. So I am asking about it now and they have not answered yet.

So this is what I got so far, there are no more errors but it is still not playing the animation.

1 Like

local c = Player.Character

Assuming this is a LocalScript, there’s no need to have a character argument for function onCharacterAdded, as you can just refer to Player.Character already.

Would it not work in the actual game if it did not belong to the owner

Yeah, plus in Studio (most of the time) it would not play the animation even if it is your animation so you would have to play it in the ACTUAL Roblox game.

For me I was trying to run an r6 animation on r15 character, make sure to go to settings => avatar and choose avater type either r6 or r15, if you want players to be able to choose their own body type then in the script where you play the animation add a little if-statement to check if the body type is r6 or r15 and play proper animation based on this

Try this:

local Players = game:GetService("Players")
local function onCharacterAdded(character)
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	while not humanoid do
		character.ChildAdded:Wait()
		if not (character:FindFirstChildWhichIsA("Humanoid") == nil) then
			humanoid = character:FindFirstChildWhichIsA("Humanoid")
		end
	end
	for _, playingTracks in next, humanoid:GetPlayingAnimationTracks() do
		playingTracks:stop(0)
	end
	local animateScript = character:WaitForchild("Animate")
	animateScript.idle.Animation1.AnimationId = "rbxassetid://3907655156"
	animateScript.idle.Animation1.Weight.Value = 5
	animateScript.idle.Animation2.AnimationId = "rbxassetid://3907655156"
	animateScript.idle.Animation2.Weight.Value = 5
	local a1 = humanoid:LoadAnimation(script:WaitForChild("Idle"))
	a1.Priority = Enum.AnimationPriority.Idle
	a1:Play()
end
local function onPlayerAdded(player)
	if player.Character then
		onCharacterAdded(player.Character)
	end
	player.CharacterAdded:Connect(onCharacterAdded)
end
-- If it's for all players on the server
for a2, a3 in next, Players:GetPlayers() do
	onPlayerAdded(a3)
end
-- If it's just for the client
onPlayerAdded(Players.LocalPlayer)

Idk if you did this already if you are using Animation Editor, set the Animation Priority to Action, Idk about Idle.