i have a little problem, How i can do that when the NPC are following you, its speed changes?
Here is the script
function findNearestTorso(pos) -- declare pos a local vector3 local list = game.Workspace:children() local torso = nil local dist = 25 -- Area to search local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if temp2.className == "Model" then temp = temp2:findFirstChild("Torso") if temp ~= nil then human = temp2:findFirstChild("Humanoid") if human ~= nil and (human.Health > 0) and (temp2.Name ~= AIName) then -- not named the same as us. if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end -- closer? end -- human? Not us. end -- Has torso? end -- Model? end -- For. Loop thru parts in Workplace return torso end -- findNearest
just get the npc's humanoid
local NPC = script.Parent local HumanoidOfNpc = Npc:FindFirstChild("Humanoid") local speed = 20 function findNearestTorso(pos) -- declare pos a local vector3 local list = game.Workspace:children() local torso = nil local dist = 25 -- Area to search local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if temp2.className == "Model" then temp = temp2:findFirstChild("Torso") if temp ~= nil then human = temp2:findFirstChild("Humanoid") if human ~= nil and (human.Health > 0) and (temp2.Name ~= AIName) then -- not named the same as us. if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude HumanoidOfNpc.WalkSpeed = speed end -- closer? end -- human? Not us. end -- Has torso? end -- Model? end -- For. Loop thru parts in Workplace return torso end -- findNearest
This should help you define NPC and HumanoidOfNpc and speed for results