I’m trying to make an NPC chat system but this error keeps happening: “Attempt to index nil with ‘Position’”
My code:
runService.RenderStepped:Connect(function()
if detected == false and chatting == false then
for i, NPC in pairs(npcs:GetChildren()) do
local Humanoid = NPC:FindFirstChild("Humanoid")
local HMR = NPC:FindFirstChild("HumanoidRootPart")
if Humanoid and HMR then
if (HMR.Position - plrHMR.Position).magnitude < 15 then --where the error is happening
detected = true
detectedNpc = NPC
eButton.Visible = true
print(NPC.Name)
end
end
end
end
I have no idea why it’s happening and it’s driving me crazy.