I am trying to make a following npc, can someone help me? I am a beginner scripter and this is my first time trying to make a following script and cant figure out how plz help :C
There
local list = game.Workspace:children() local dist = 500 -- Change to the distance you want the Zombie to find people local time = 0.1 --Change to how long you want the Zombie to find and chase people (I recommend 0.1) while true do wait(time) for x = 1, #list do local temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then local temp = temp2:findFirstChild("Torso") local human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - script.Parent.Torso.Position).magnitude < dist then script.Parent.--[[Zombies//Change to name of whatever you put this into]]:MoveTo(temp.Position, temp) end --Then remove the text and these: -- [[ ]] end end end end
Here try this, make sure it's in a model with a Humanoid, and also make sure the model is not anchored.
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 1000 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("Torso") 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(0.1) local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end