Animation loop doesn't work

Hello, so I’ve made a very simple script to play a looped animation when the tool is equipped.

local tool = script.Parent
local anim = Instance.new("Animation")
anim.AnimationId = "http://www.roblox.com/Asset?ID=5215451472" --replace with id
local track
tool.Equipped:Connect(function()
    track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
    track.Priority = Enum.AnimationPriority.Action
    track.Looped = true
    track:Play()
end)
tool.Unequipped:Connect(function()
    if track then
        track:Stop()
    end
end)

For some reason, the animation plays looped on the client but shows only one time on the server.
And when I try to do the same script in a script and not a local script, the opposite happens, the server is looped but for the client the animation isn’t looped.
I’ve tested it with some friends, here are some video examples:


Thank you for your time :slight_smile:

1 Like

To get the desired looped effect you need to set the animation to looped in the editor:

Here is a image of the button you need to press:

Here is a link to more info on the editor: Using the Animation Editor

2 Likes

Don’t think you understood what I meant, I believe it’s a scripting problem.
The user can see his animation playing but not other players.

1 Like

When you did LoadAnimation, did you do it inside the humanoid?

Looked at your code again, it seems like you did. Maybe play the animation in the server?

You’re playing the animation the client-side that’s why, if you wish to make the animations appear for everyone, you can either play the animation on the server, or use a AnimationController which makes animation replicate if played on the client.

For some reason, if I play the animation on the server, it shows the animation for the server but not the client

If you play the animation on the server it should show up for all clients. Are you sure that it’s doing things right?

Please read the dev wiki for Animation:

If an Animator is a descendant of a Humanoid or AnimationController in a Player’s Character then animations started on that Player’s client will be replicated to the server and other clients.

In his case, it was loaded in the humanoid. LoadAnimation creates an Animator object.

There is a bug with setting the Looped property via script rather than in the Animation editor.

To avoid this you can change the property in the animation editor, and then publish the animation.

When switching to the server view, you can see that the animation is playing for a second before stopping, suggesting that the looped property itself isn’t replicated across the boundary.

4 Likes