Hey, sorry if it sounds like im asking for alot, but can anyone tell me the lines of code needed to play an animation, and make it loop? I dont know a lick of Lua C, thanks!
To play an animation for a player you can do the following steps.
- Reference the local player, character and the humanoid in a local script
local player = game.Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character.Humanoid
- Create an animation and parent it to the character if the character doesn’t have the animation yet
local standAnimation = nil if not character:FindFirstChild("standAnimation") then standAnimation = Instance.new("Animation") standAnimation.AnimationId = "rbxassetid://animationIdNumber" standAnimation.Name = "standAnimation" standAnimation.Parent = character end
- Load the animation onto the humanoid, this returns an
AnimationTrack
Object so that you can play the animation later with it!local animationTrack = humanoid:LoadAnimation(standAnimation)
- If the animationTrack was created then you can set the
Looped
property totrue
so that it will loop the animation, then to play the animation on the track, just run the:Play()
method and it will play!if animationTrack then animationTrack:Play() end
After everything is complete your script should look like this:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character.Humanoid
local animationTrack = nil
local standAnimation = nil
if not character:FindFirstChild("standAnimation") then
standAnimation = Instance.new("Animation")
standAnimation.AnimationId = "rbxassetid://animationIdNumber"
standAnimation.Name = "standAnimation"
standAnimation.Parent = character
end
if standAnimation
animationTrack = humanoid:LoadAnimation(standAnimation)
if animationTrack then
animationTrack.Looped = true
animationTrack:Play()
end
end
2 Likes
This developer hub article helped me a lot when I was scripting animations:
I always refer to the developer hub first before asking on the devforum!
1 Like
thanks! this helped alot!
30charrrrrrsssss