I’ve tried to find an answer to this for a while and all of the resources I could find told me to copy the Animate script from my player model and paste it in the Npc model and change it to a server script. Not only does this not work for me, I’m also instancing the player model mid-game and can’t make such preparations before the game runs.
I want to have a script that I can replicate and give each npc so that they have a walking animation instead of just gliding to their destination. How can I give an Npc a walking animation without copy and pasting the Animate script from my own model?
I’m really just looking for a simple, ‘one size fits all’ kind of code that will give the npc only a walking animation.
I’ll take a crack at it, this is untested code. Simply wrote it up, if you have any questions let me know.
Make sure all the NPC’s are inside a folder named NPC_Folder.
Make sure all NPC’s have a Humanoid named Humanoid.
Make sure the Animation is within the NPC, named Walking.
That should be about it.
local NPCs = game.Workspace:WaitForChild("NPC_Folder")
for i, NPC in pairs(NPCs:GetChildren()) do
if NPC.Name == "NPC" and NPC:FindFirstChild("Humanoid") then
local Humanoid = NPC:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:GetPropertyChangedSignal("WalkToPoint"):Connect(function()
local Humanoid_State = Humanoid:GetState()
if Humanoid_State == Enum.HumanoidStateType.Running then
local WalkingAnimation = NPC:FindFirstChild("Walking")
local Animation = Humanoid:LoadAnimation(WalkingAnimation)
Animation:Play()
elseif Humanoid_State == Enum.HumanoidStateType.None then
local RunningAnimations = Humanoid:GetPlayingAnimationTracks()
for i, animation in pairs(RunningAnimations) do
if animation.IsPlaying == true then
animation:Stop()
end
end
end
end)
end
end
end