Playing an animation

How would I make it where an animation would play on a dummy in workspace. Right now I have a local script in StarterPlayerScripts and a dummy in workspace. I would like the dummy to play a certain animation from the local script but don’t know how to start. Thanks

You could simply do something like this -

local Humanoid = script.Parent.Humanoid
local AnimationID = script:WaitForChild('AnimationID')
local Animator =Humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")

animation.AnimationId =  "rbxassetid://"..AnimationID.AnimationID
local real= Animator:LoadAnimation(animation)
real.Looped = true
real:Play()

image

In this case, that animation is for R15.
You could do the same with R6 with some accordingly changes.

1 Like

All you have to do is load the animation onto the local dummy’s Animator (make sure to put an animator instance in the dummies humanoid). With the follow code in a local script in the player’s character:

local dummy = "grab your dummy from it's location"
local humanoid = dummy:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId =  "rbxassetid://id goes here"
local track = Animator:LoadAnimation(animation)
track.Looped = true
track:Play()
1 Like

I wouldn’t recommend making the server do animations, just have every client handle their own animation for the dummy.

1 Like

In this example it doesnt really matter, he can play it from both sides. If it was more complicated, then it’d have been a different case.

1 Like

In this case yea, but no need to teach bad practices, in a real game the server rarely ever does animations. Also, don’t use Humanoid:LoadAnimation(animation). Cut out the middle man and go straight to the Animator. If you call Humanoid:LoadAnimation(), it’ll have to check if an animator exists or not, excess code being ran when it’s not needed.

1 Like

Thanks but its giving me an error "AnimationID is not a valid member of Animation “Workspace.Character1.Script.AnimationID”

Not on PC right now, but replace AnimationID with the property that resembles where you put the ID of the animation.

1 Like

I did that I think.

And this is the script im using -

local Humanoid = script.Parent.Humanoid
local AnimationID = script:WaitForChild('AnimationID')
local Animator = Humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")

animation.AnimationId =  "rbxassetid://"..AnimationID.AnimationID
local real = Animator:LoadAnimation(animation)
real.Looped = true
real:Play()

Still giving me the same error by the way.

The animation under the script IS the animation, your animation’s AnimationId property has to have the id of the animation you want to play or it loads nil

local Humanoid = script.Parent.Humanoid
local AnimationID = script:WaitForChild('AnimationID')-- This IS the animation but it's AnimationId property is nil
local Animator = Humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")

animation.AnimationId =  "rbxassetid://"..AnimationID.AnimationID
local real = Animator:LoadAnimation(AnimationID)
real.Looped = true
real:Play()
1 Like

Check out these articles which have basics of loading and playing animations
https://developer.roblox.com/en-us/api-reference/function/Animator/LoadAnimation
https://developer.roblox.com/en-us/api-reference/property/Animation/AnimationId

1 Like

Ok thanks, I ended up fixing it. Thank you everyone else as well.