How to make npc run after local player

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want an Npc to walk after a local player. You know like in obbys the monster(NPC) only walks after you even tough there are players near the monster, so locally.

  2. What is the issue? Include screenshots / videos if possible!
    I have tried everything and it doesnt seem to work. I tried cloning an npc from replicated storage with a local script but that didnt work.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i cant find anything

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Hello!

To get a Model to move towards a point, you can use Humanoid:MoveTo(position: Vector3), so what you can do is getting the Local Player, then get the RunService and connect it with either the Stepped or Heartbeat event like this:

RunService.Heartbeat:Connect(function()

end)

Inside, you can check if the Player has a character, if it is so, then get the Position of it and pass it into the MonsterHumanoid:MoveTo() function.

Edit: Accidentally switched up Model with Humanoid, fixed it!

This should work in a Local Script, and I hope I could help!

should i put the local script inside of the npc or where? And thanks for the reply!

Yes, preferably inside your NPC Model, so you can reference it by using script.Parent. I hope I could help further!

Hi, I tried your suggestion but it didnt seem to work.
This is the local script located inside of the npc model:

local plr = game.Players.LocalPlayer
local RunService = game:GetService("RunService")

RunService.Heartbeat:Connect(function()
	if plr.Character then
		script.Parent:MoveTo(plr.Character:FindFirstChild("HumanoidRootPart").Position)
	end
end)```

The npc just stands still

LocalScripts don’t run under Workspace unless its a descendant of the player’s character. Place it somewhere else:


local plr = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local model = ... -- put the directory to the npc model here

RunService.Heartbeat:Connect(function()
	if plr.Character then
		model:WaitForChild("Humanoid"):MoveTo(plr.Character:GetPivot().Position)
	end
end)

ooo that worked but how do i fix it so that i dont need to be super close to the npc in order for it to follow

And another problem. I want the npc to onlt follow the local player but yet it still follows everyone in the game. Any ideas on how to achieve this?

Hello again!

LocalScripts don’t run under Workspace unless its a descendant of the player’s character.

Oh sorry, my bad, I never noticed that scripts will only work like this.

I don’t know if there is a better way of doing this (and if there is one, please correct me), but how I got it was by making the existence of the model local too, by cloning it inside a LocalScript into the workspace from the ReplicatedStorage.

Since every Instance has a :Clone() function, you could place your model inside the ReplicatedStorage, and then clone it into the world inside a StarterPlayerScript like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local model = ReplicatedStorage.MODEL_PLACEHOLDER:Clone()

This has the benefit that you can easily use, for example, the same monster model a number of times without referencing every single instance of them inside the workspace, but don’t forget to change the Position of the model with Model:PivotTo(cframe) if you want it somewhere else.

Again, I hope I could help further!

Ohh, thx, I will try it out once i get home. I will keep you updated for further questions. And yet again, Thanks!