Attempt to index nil with 'Position'

Please help me, my script was working perfectly fine then one day it just stopped it keeps saying position is nil even tho all my other scripts work perfectly fine

its the “if (player.Character.pullbox.Position - hrp.Position).magnitude < dist then” line that is giving me issues

my script:

local dist = 10
local TweenService = game:GetService("TweenService")
local debris = game:GetService("Debris")
local ishit = false

script.Parent.OnServerEvent:Connect(function(player)
	ishit = false
	while ishit == false do
		wait(0.001)
		local pos = player.Character.pullingbox
	for i, v in pairs(game.Workspace:GetChildren()) do
		local hum = v:FindFirstChild("Humanoid")
		local hrp = v:FindFirstChild("HumanoidRootPart")
		local torso = v:FindFirstChild("Torso")
		if hum and torso and v ~= player.Character then
				if (player.Character.pullbox.Position - hrp.Position).magnitude < dist then
					print("hit")
					hum:TakeDamage(20)
					
					local stun = Instance.new("StringValue")
					stun.Parent = hrp
					stun.Name = "Stun"
					
					
					hrp.Anchored = true
					debris:AddItem(stun,1.25)
					
					
					ishit = true
					player.Character.pullbox:Destroy()
				local goal2 = {}
				goal2.CFrame = pos.CFrame
				local info2 = TweenInfo.new(0.25,Enum.EasingStyle.Cubic,Enum.EasingDirection.Out)
				local tween2 = TweenService:Create(hrp,info2,goal2)
					tween2:Play()
					wait(0.5)
					tween2:Destroy()
					pos:Destroy()
					wait(0.75)
					if not player.Character.HumanoidRootPart:FindFirstChild("1StunM1") and not player.Character.HumanoidRootPart:FindFirstChild("2StunM1") and not player.Character.HumanoidRootPart:FindFirstChild("3StunM1") and not player.Character.HumanoidRootPart:FindFirstChild("4StunM1") and not player.Character.HumanoidRootPart:FindFirstChild("5StunM1") then
						hrp.Anchored = false
						end
				


				end
			end
		end
	end
end)

please help me if you can.

Could you maybe tell us where the error pops up? What line, add comment there, what have you already tried to fix it?

1 Like

The error has to be occuring on this line:

if (player.Character.pullbox.Position - hrp.Position).magnitude < dist then

CardSenju, can you please double check that “pullbox” is indeed inside the player model? I believe that the code is erroring because it is not created

Well yeah, but still he has to learn how to ask for help, if he posts bigger scripts where you index Position way more many times it wouldn’t be clear, so I’m just asking for the next time for him to know how to ask better.

Anyway, the issue you are having is the pullbox being nil as I don’t think HumanoidRootPart will be nil.
Make sure the pullbox is inside the player character and that you are referencing it with the right name, you could have a typo in referencing it like pullbox instead of Pullbox. Check all of those and let us know after.

yes “pullbox” is inside of the player ive checked multiple times
ive even changed it to just

if (player.Character.HumanoidRootPart.Position - hrp.Position).magnitude < dist then

and it still gives me the “Attempt to index nil with ‘Position’” error

edit: yea no matter what i put there it comes back as nil even if i create a part using the script it comes back as nil and i have NOOO idea why

Nvm i fixed it i found out that the issue was the hrp.Position idk what was wrong but i fixed it i just changed it from hrp.Position to torso.Position

:smiley: