Again, I've searched online for this and tried various ways, for example changing the Dist = 10000 to minDist = (whatever number) and also BestDist = (whatever number). I don't know if that was the right thing to do, sorry, Iam a total noob at lua language. Basically, I want the NPC to follow the player when the player reaches a certain distance from it. Please also tell me if there is a need for a different script or something, Thanks a lot. This is my chase script, what it does is, wherever I place the NPCs, they search the whole map for a player and follow him, e.g. from the other end of the map to the other, which is not what I want. -
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 = 10000 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
Closed as Not Constructive by User#19524
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?