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

AnimationTrack:Play() does not play the animation. Why is this?

Hi. For a while I have been having trouble with getting animations to play. I have the following LocalScript in StarterPack:

local hum = game.Players.LocalPlayer.Character.Humanoid
local ani = Instance.new("Animation")
ani.AnimationId = "http://www.roblox.com/asset/?id=180436148"
local anit = hum:LoadAnimation(game.Players.LocalPlayer.Character.Animate.climb.ClimbAnim)
anit.KeyframeReached:connect(function(keyframeName)
	print(keyframeName)
end)
while wait(1) do
	print("Run")
	anit:Play()
end

In the output I only get "Run" once about each second. No animation plays from this.

EDIT: It appears that the animation plays, when using a dedicated client with server. Why is this?

4 comments

0

Could be the Setting the animation is on.

0

Using my own or another standard animation yields the same result.

0

I meant settings like, Core,Idle,Movement,and action.

0

Hi. I believe that I used an animation I created, that has the Movement priority. In any case, I believe it would print the keyFrameName from the event, if it truly loaded.

1 answer

✓ Accepted answer

For your anit variable, you're not loading your actual animation and this is why your animation doesn't play. You need to do hum:LoadAnimation(ani) so that the animation loads and then you can play it using the Play method.

Your final script should look something like this:

local player = game.Players.LocalPlayer --Gets the local player
local char = player.Character or player.CharacterAdded:wait() --If the character is available, it uses the character property, otherwise it waits for the character then returns it.
local hum = char:WaitForChild("Humanoid") --Waits for the character's humanoid.

local ani = Instance.new("Animation")
ani.AnimationId = "http://www.roblox.com/asset/?id=180436148"
local anit = hum:LoadAnimation(ani) --Load the actual animation.

anit.KeyframeReached:connect(function(keyframeName)
    print(keyframeName)
end)

while wait(1) do
    print("Run")
    anit:Play()
end

I hope my answer helped you. If it did, be sure to accept it.

More information on this subject here.

6 comments

0

Hi. You probably missed it, but anit is already getting loaded with hum:LoadAnimation(...). You might have missed it due to the automatic line break on the site.

0

I know that. I'm saying you're loading the climbing animation, not the actual animation you created.

0

I was switching around with those for testing. None of them worked. I should have written that.

0

Edited my answer.

0

Thing is, what caused this is a bug in Roblox itself, it seems. The animation only loads when testing on a dedicated (test) client and server. Rather than pressing F5.

0

That's probably to be expected. Play Solo has way more bugs than Client/Server mode, I usually use Client/Server mode because it replicates a ROBLOX server and allows me to find errors which you couldn't find in Play Solo.

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