Hey! I have a script that creates an NPC version of a player and I am wondering how I can load their idle animation onto the NPC. I know how to get the player’s idle, but not how to use it.
I have tried several attempts, and using an animation that I own (as in uploaded myself to Roblox) it works, but Roblox’s animations don’t. I also tried the whole copy the “Animation” localscript and then change it to script method but that only plays the default idle - not the player’s idle. I also tried downloading an Idle animation that Roblox made which gave me a group with multiple animations and using one of those worked - but it’s not the full Idle nor do I know how to get that from the full Idle animation ID.
When you were initially scripting the animation to play on the humanoid, not using the players animate script copy and paste. Was it inside a server or local script?
You can make a server script inside the NPC and manually play the idle animation like this
local animation = script:WaitForChild('Animation')
local humanoid = script.Parent:WaitForChild('Humanoid')
local idle = humanoid:LoadAnimation(animation)
idle:Play()
A side note, you can’t animate an NPC using a local script. So the reason why the copy and paste for the animate script wouldn’t work was because local script run only if it’s a descendant of a player instance I think.
So you can
Copy and paste the animation script inside the NPC
Copy the script using Ctrl + A
Insert a server script inside the NPC
Paste the script inside the server script and do the following
On lines 714- 752 paste this.
--[[
-- setup emote chat hook
game:GetService("Players").LocalPlayer.Chatted:connect(function(msg)
local emote = ""
if (string.sub(msg, 1, 3) == "/e ") then
emote = string.sub(msg, 4)
elseif (string.sub(msg, 1, 7) == "/emote ") then
emote = string.sub(msg, 8)
end
if (pose == "Standing" and emoteNames[emote] ~= nil) then
playAnimation(emote, EMOTE_TRANSITION_TIME, Humanoid)
end
end)
-- emote bindable hook
if FFlagAnimateScriptEmoteHook then
script:WaitForChild("PlayEmote").OnInvoke = function(emote)
-- Only play emotes when idling
if pose ~= "Standing" then
return
end
if emoteNames[emote] ~= nil then
-- Default emotes
playAnimation(emote, EMOTE_TRANSITION_TIME, Humanoid)
return true
elseif typeof(emote) == "Instance" and emote:IsA("Animation") then
-- Non-default emotes
playEmote(emote, EMOTE_TRANSITION_TIME, Humanoid)
return true
end
-- Return false to indicate that the emote could not be played
return false
end
end
]]
The id contained in HumanoidDescription.IdleAnimation isn’t an actual animation id which is why this wasn’t working. It returns an id that would bring you to as an example; https://www.roblox.com/catalog/619535834/Zombie-Idle. So I used InsertService to insert it and then grab the actual animation. Which looked like the following:
local model = game:GetService("InsertService"):LoadAsset(humanoid.HumanoidDescription.IdleAnimation)
local animation = model.R15Anim.idle.Animation2
local animationTrack = humanoid:LoadAnimation(animation)
animationTrack.Looped = true
animationTrack:Play()