Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
AmiracIe 175
9 years ago

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!

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. Discern 1007 — 9y
0
I've changed it to the correct asset ID, but it still doesn't work. :( AmiracIe 175 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

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!

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. :( AmiracIe 175 — 9y
0
I didn't see your edit. It works now; thank you very much! AmiracIe 175 — 9y
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. Discern 1007 — 9y
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. Discern 1007 — 9y
Ad

Answer this question