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

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

Asked by 9 years ago

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?

0
Could be the Setting the animation is on. woodengop 1134 — 9y
0
Using my own or another standard animation yields the same result. frederikam 15 — 9y
0
I meant settings like, `Core`,`Idle`,`Movement`,and `action`. woodengop 1134 — 9y
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. frederikam 15 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

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.

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. frederikam 15 — 9y
0
I know that. I'm saying you're loading the climbing animation, not the actual animation you created. Spongocardo 1991 — 9y
0
I was switching around with those for testing. None of them worked. I should have written that. frederikam 15 — 9y
0
Edited my answer. Spongocardo 1991 — 9y
View all comments (2 more)
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. frederikam 15 — 9y
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. Spongocardo 1991 — 9y
Ad

Answer this question