-
What do you want to achieve? I want to achieve the following script
-
What is the issue? It is printing in output "Attempt to index nill with position
-
What solutions have you tried so far? I tried many editions of code and also I asked in discord server how to fix it
script
local NPC = script.Parent
local SelfHum = script.Parent.Humanoid
local SelfHRP = script.Parent.Torso
while wait(1) do
for i, v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("Humanoid") and v~= NPC then
local PeopleHRP = v:FindFirstChild("HumanoidRootPart")
local magnitude = (SelfHRP.Position - PeopleHRP.Position).Magnitude
if magnitude <= 100 and v~= NPC then
SelfHum:MoveTo(PeopleHRP.Position)
else
SelfHum:MoveTo(Vector3.new(math.random(1,100),1,math.random(1,100)))
end
end
end
end
Line error is 15
local magnitude = (SelfHRP.Position - PeopleHRP.Position).Magnitude
It is also working on one npc but on the other the script is printing error