Can't make Animation/Code work

Currently working on coding some animations for my up and coming game.
I’ve followed everything known to my knownlage but cannot seem to find a reason to my error.

I’ve put a LocalScript into StarterCharacterScripts
Animation IDs were added into the “Animation” under the LocalScript

--------------------------------------------------------------

-- || Client-Sided LocalScript created by: @Joeys2Valid
-- || Created on September 27, 2024	at 11:41 PM (23:41)

--------------------------------------------------------------





-- // MAIN SCRIPT
--------------------------------------------------------------
local animation = script:WaitForChild("Animation")
local humanoid = script.Parent:WaitForChild("Humanoid")
local AnimationTrack = humanoid:LoadAnimation(animation)

AnimationTrack:Play()


--[[

--------------------------------------------------------------
N O T E S


--------------------------------------------------------------
]]

Thank you for your time for reading this/and trying to help in advance.

4 Likes

And what is your error? Also it’s better if you load the animation on the Animator instance inside the players humanoid

local animation = script:WaitForChild("Animation")
local player = player.Character or player.CharacterAdded:Wait()
local humanoid = player.Character:WaitForChild("Humanoid")
local Animator = humanoid:FindFirstChildWhichIsA("Animator") or Instance.new("Animator").Parent = humanoid
local AnimationTrack = Animator:LoadAnimation(animation)

AnimationTrack:Play()

It should work

2 Likes

The animations wont load/do what they’re supposed to be doing.

I’ll give your code a try.

1 Like

I’m not sure where that is, roblox studio has changed alot, any feedback?

1 Like

Where the Animator is? Roblox either creates it inside the players Humanoid, or you have to do it yourself (like in the code i provided)

1 Like

I mean I put your code in but I’m still getting errors.

1 Like

my bad

local animation = script:WaitForChild("Animation")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:FindFirstChildWhichIsA("Animator") or Instance.new("Animator").Parent = humanoid
local AnimationTrack = Animator:LoadAnimation(animation)

AnimationTrack:Play()

I’m not sure if it’s something on my end but it’s not working let me send the folder

You probably have to delay the animation a little bit until the player loads completely, try adding a task.wait(10) before loading the animation

Still not loading.

image

ID’s are in every single one, do I need to do different codes for each different one?

Go into studio settings, turn on Show Active Animation Asset, and check if the animation loads or not, it might just be overriden

Does seem to be reading my animations.

image
**

My bad i just realised the script has an error, i haven’t tested it until now, this seems to be working fine for me.

local animation = script:WaitForChild("Animation")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:FindFirstChildWhichIsA("Animator") or Instance.new("Animator", humanoid)

task.wait(5)

local AnimationTrack = Animator:LoadAnimation(animation)
AnimationTrack:Play()

Code worked for only one of the animations. I might be missing a step somewhere

It only works for one of the animations, as you are only playing it once, do you want it to run all of them one by one, or at the same time?

It’s just a running animation walking and idle
I’m trying to do them one bye one

local animation = script:WaitForChild("Animation")
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:FindFirstChildWhichIsA("Animator") or Instance.new("Animator", humanoid)

task.wait(5)

for _,v in script:GetChildren() do
    if not v:IsA("Animation") then return end

    local AnimationTrack = Animator:LoadAnimation(animation)
    AnimationTrack:Play()
    AnimationTrack.Ended:Wait()
end

Doesn’t seem to work

430 characters

My bad again, i might have to start testing my scripts before replying :sob:

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local Animator = humanoid:FindFirstChildWhichIsA("Animator") or Instance.new("Animator", humanoid)

task.wait(5)

for _,v in script:GetChildren() do
	if not v:IsA("Animation") then return end

	local AnimationTrack = Animator:LoadAnimation(v)
	AnimationTrack:Play()
	AnimationTrack.Ended:Wait()
end

Still doesn’t seem to be working