How would I make this animation script play 3 idle animations randomly?

So… I am trying to make animation server script for a NPC that will have the same idle animations as a player would. I am familiar with running 1 animation on a npc with AnimationController but not with 2 or more.

So far I have a folder with a string value named “idle”, with 3 animations as children, and each animation with a number value named “Weight”… kinda like how Roblox’s Animate Script is set up.

Ive also tried putting the roblox animate script as a Server Script with all the children values and deleted the “Emote chat hook” section of the script. It kinda worked except my NPC was just in the falling animation state the whole time. Also, the humanoid root part couldnt be anchored or welded to a “holder” part so I gave on that and tried making my own.

Anyways, heres the script I manage to put together… kinda just wondering what to put to bring it all together ya know

local Idle1 = game.Workspace.Animations:WaitForChild("DefaultAnims"):WaitForChild("idle"):WaitForChild("Idle1")
local Idle2 = game.Workspace.Animations:WaitForChild("DefaultAnims"):WaitForChild("idle"):WaitForChild("Idle2")
local Idle3 = game.Workspace.Animations:WaitForChild("DefaultAnims"):WaitForChild("idle"):WaitForChild("Idle3")

Idle1.Weight.Value = 9
Idle2.Weight.Value = 1
Idle3.Weight.Value = 1

local animControllerBlackSmith = game.Workspace:WaitForChild("Blacksmith"):WaitForChild("AnimationController")

local Idle1Track = animControllerBlackSmith:LoadAnimation(Idle1)
local Idle2Track = animControllerBlackSmith:LoadAnimation(Idle2)
local Idle3Track = animControllerBlackSmith:LoadAnimation(Idle3)

Idle1Track:Play() ------ something here I need to do?



How I would solve this is by putting each animation into an array and then selecting a random index from that array to play an animation.

math.randomseed(tick()) -- Makes numbers more random

local animations = {anim1, anim2, anim3}

local randomIndex = math.random(1, #animations)

local randomAnimation = animations[randomIndex] -- Indexing the animation using whatever the random index is.


I mean, that works If I want 1 animation to play randomly.

but I messed around with it anyways

I merged that with my code and put it into a loop and modified roblox’s default idle animations by making their priority to Action. That kinda worked, with choosing 1 out of the 3 animations but it doesnt transition to another animation smoothly and it doesnt have 1 animation playing most of the time.

What Im trying to find out here is how to make it idle like a player would if the player was standing there. Like have the main idles then every once of a while it would turn the head or do a wave or something. Im trying to figure out how to get the weights to work

I messed with the animate script again and got it to work instead using Animation Controller and deleting certain parts of the script. The NPC now has the same animations as a player would and doesn’t have the humanoid messing things up anymore.

Thanks for helping though

1 Like