Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why doesn't my animation fire when a player enters the game?

Essentially, I want a player to have this dance when he or she enters the game. I'm pretty sure I did everything right, but the animation still doesn't fire:

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(character)
		
local animation=Instance.new("Animation")

animation.AnimationId="http://www.roblox.com/Asset?ID=160934457"

local animTrack=character.Humanoid:LoadAnimation(animation)
wait(3)
animTrack:Play()
print("test")
	end)
end)

There aren't any errors in the output, and it prints "test".

Your help would be great!

2 comments

1

I haven't looked at other parts of the script, but the asset is only subtracted by 1 when it's a shirt, pants, or t-shirt. It's an animation, so don't subtract one. So the ID should be 160934458 instead of 160934457 in the script.

0

I've changed it to the correct asset ID, but it still doesn't work. :(

1 answer

✓ Accepted answer

Everything seems fine except the Asset ID (like Discern pointed out), if there is anything in the output please post it.

EDIT: When using an animation you must play it from a local script! So in this case just put a local script in StarterPack or StarterGui and it should work when the player spawns.

Use the code below in a LocalScript

repeat wait()
player = game.Players.LocalPlayer
character = player.Character
until (player) and (character)

local animation = Instance.new("Animation", character)
animation.AnimationId = "http://www.roblox.com/Asset?ID=160934458"
local animTrack = character.Humanoid:LoadAnimation(animation)
wait(3)
animTrack:Play()
print("test")

If you are still having trouble, then just read through the wiki article below carefully.

http://wiki.roblox.com/index.php?title=Animations

If this works, then don't forget to mark this as the answer!

4 comments

0

It doesn't work, unfortunately. I read that wiki article you sent me and changed it to be a LocalScript, but it still didn't work. :(

0

I didn't see your edit. It works now; thank you very much!

1

Actually, this code can be run from a regular script. The error that he had was on lines 8. He was trying to use a Method on a Humanoid before the Humanoid existed (Since the script runs so fast). All he had to do was move the wait(3) back a line and change the ID, and it would be a functioning script.

1

You have a repeat wait() until player and character, which is just enough time to allow the Humanoid to be created in the game.

This discussion is preserved as it was. New answers, comments, and votes are closed.