You can write your topic however you want, but you need to answer these questions:
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.
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.
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!
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!
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
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)
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.