I’ve been making an NPC that follows the closest player, but I want to make it so that the NPC does not follow too closely. It runs normally without the parameter at the bottom of the function, but does not run at all with it. Here is the function:
1 Like
Ima just ignore everything youre doing above the while task.wait() do
. Anyways, you can just check the magnitude of the player and the NPC doing, (NPC.HumaniodRootPart.Position - target.Position).Magnitude
then move it closer if they’re too far apart
while task.wait() do
local target = findNearestTorso(positionTorso) -- Im assuming this is the torso of Player
if target ~= nil then
if (NPC.HumaniodRootPart.Position - target.Position).Magnitude > 5 then -- Checks if NPC is farther than or equal to 5 studs and moves him closer.
humanoid:MoveTo(--blah blah blah please format your code which can be done by clicking the cog wheel and clicking "preformatted text" when you're sending a reply or message)
end
positionTorso = script.Parent.HumanoidRootPart.Position
end
If you didn’t read the comment the Magnitude > 5
checks if the NPC is farther than 5 studs from the player, if it is, move NPC closer.
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.