Hey, im having an issue. Issue is: “attempt to index nil with position”
here’s the code.
if v:FindFirstChild("Humanoid") and v.Humanoid.Health > 0 and v ~= character and v:FindFirstChild("Block") == nil then
local p1 = character.HumanoidRootPart.Position
if (p1 - v.Parent:FindFirstChild("HumanoidRootPart").Position).Magnitude < 50 then
It looks good, but we cant tell what is character and through which table are u looping. From what I have seen the problem must be in character or in v
The error lies somewhere in either lines 3 or 4, could you add some print statements (Indicating v) so we know that the variable you’re trying to create is valid to the script?
pcall(function ()
if v:FindFirstChild("Humanoid") and v.Humanoid.Health > 0 and v ~= character and v:FindFirstChild("Block") == nil then
local p1 = character.HumanoidRootPart.Position
if (p1 - v.Parent:FindFirstChild("HumanoidRootPart").Position).Magnitude < 50 then
it is very difficult to help you if you don’t give us more information.
if v:FindFirstChild("Humanoid") and v.Humanoid.Health > 0 and v ~= character and v:FindFirstChild("Block") == nil then
local p1 = character.HumanoidRootPart.Position
if (Vector3.new(p1) - Vector3.new(v:FindFirstChild("HumanoidRootPart").Position)).Magnitude < 50 then
its an annoying bug, for some reason when you create a variable of a vector, it converts into a (0,0,0) format with not context. @XurySenpai
if v:FindFirstChild("Humanoid") and v.Humanoid.Health > 0 and v ~= character and v:FindFirstChild("Block") == nil then
local p1 = character.HumanoidRootPart.Position
if (p1 - v.Parent:WaitForChild("HumanoidRootPart").Position).Magnitude < 50 then
Hey, I tried doing this. This almost worked but not fully, it still can’t find the humanoidrootpart for some weird reason. This is my current code:
local p1 = character:WaitForChild("HumanoidRootPart").Position
if (Vector3.new(p1) - Vector3.new(v:WaitForChild("HumanoidRootPart").Position)).Magnitude < 50 then
Maybe because when your actually running the game, there is no player? I see that you are trying to get the magnitude of two players and displaying it. You may want to use the pcall function so the script doesn’t need to run into errors.
So you might want to run your code in a pcall function.
Hello everyone, I’ve fixed the bug. i kinda let it be for a while but it’s fixed. It was quite a stupid bug and I’m ashamed for not having realized it. There were some NPCs without an humrp. Yeah obviously it won’t find it if there’s none. Anyways that’s it.