NPC made using CreateHumanoidModelFromUserId doesn't animate when calling MoveTo

I’m not very familiar with handling NPCs, all I want to make is an NPC that walks around in a random manner. I came up with the following script:

local userId = 1

local model = game.Players:CreateHumanoidModelFromUserId(userId)
model.Name = game.Players:GetNameFromUserIdAsync(userId)
local humanoid = model:FindFirstChildWhichIsA("Humanoid")
model.Parent = workspace 
while true do
	humanoid:MoveTo(model:GetPivot().Position+Vector3.new(math.random(-10, 10), 0, math.random(-10, 10)))
	humanoid.MoveToFinished:Wait()
end

But currently when I test it the NPC doesn’t do the walk animation, it just “floats” around. I want it so the NPC walks like normal players do, Ideally using the animation related to their user id.

1 Like

This is due to the lack of Animate script
to obtain one, press play, find it in your character, copy it, press stop, paste it into the character before you call moveto

Hi, the Animate script already exists in characters created using the CreateHumanoidModelFromUserId method. After the issue appeared, I tried to replace it with the Animate script of the player character, but the behavior remained the same(the NPC still floats around).

If you are using MoveTo on the server, try turning the Animate script into a server script and just remove the emote related functions and instances. Thats how it fixed itself for me when I tried it

Copy the contents, create a new server script and set the run context to client and paste in the code. After that delete the emote function

You can still call it on the server and get the animations on the client.

Copy the contents, create a new server script and set the run context to client and paste in the code. After that delete the emote function

You must copy the client animate script code and instances to a server script. Also remove anything relating to emotes in the script, just so it doesn’t error. (like @Baltic256 said)

1 Like

To fix it I ended up converting the Animate script to a server script and setting the RunContext to either Server or Legacy(both work). I also removed the emote related and .Chatted related code so that there’re no client-related errors. I marked your reply as a solution since you were the first to point it out, but I also appreciate the replies of @Baltic256 and @Minerdude_alt.

It’s a bit of a shame I have to fork the Animate script, because it may change by Roblox at any moment. If anyone has a solution that doesn’t require forking it, it’s welcome here.

Setting it to client should work too and it should bring better performance because you won’t need a much replication

That works too, I was just being silly and testing using the “Run” setting that doesn’t spawn characters.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.