How would i make an npc follow a specific player only (like an owner). I found this script but it gets the npc to follow everyone. (my last question got taken down for being “too broad”, but i dont know what to do or how to get an answer, ive searched everywhere) [ oh and i already asked this question but i didnt get an answer ]
script:
local larm = script.Parent:FindFirstChild("HumanoidRootPart") local rarm = script.Parent:FindFirstChild("HumanoidRootPart") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 100 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("HumanoidRootPart") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end while true do wait(math.random(1,5)) local target = findNearestTorso(script.Parent.HumanoidRootPart.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end
First of all, that's a free model, and it's pretty laggy, but if you're ok with that, sure, let me explain:
the 2 variables you have set "larm" and rarm" are pretty the same, and you don't need them.
What that script does is looping through all the players position EVERY TIME. and when it's close of it, it follows.
If you want it to go to a specific player, do this in the line 25:
if temp2.Name == "YOURNAME HERE" then
and that's all, also i again don't recommend using that, it's really old, laggy, and messy. So do whatever you want. Hope I helped.
Insert a Script in ServerScriptService and add this inside it
game.Players.PlayerAdded:Connect(function(plr) -- player added if plr.Name == "PLAYERNAME" then -- Put the player name in between the " " repeat wait() until workspace:FindFirstChild(plr.Name) -- waits for character to load local NPC = game:GetService('ServerStorage'):WaitForChild('NPC'):Clone() -- clones npc NPC.Parent = workspace -- parents it to workspace while wait() do -- loop NPC:WaitForChild('Humanoid'):MoveTo(plr.Character:WaitForChild('UpperTorso').Position + Vector3.new(-3,0,4)) end end end)
Then put your NPC Into ServerStorage make sure its called "NPC" and it should work
(If you are using R6 change "UpperTorso" to "Torso")