Attempt to index nil with 'Position

Hello developers,

I have some problem with make interacting GUI. There is an error that says

attempt to index nil with 'Position

I tried to search in Roblox wiki but I hardly understand it

thi is my script:

local door = game.Workspace.Bar.Door

local player = game.Players.LocalPlayer
local char = player.Character
local RHP = char:FindFirstChild("HumanoidRootPart")


local bill = script.Parent.BillboardGui
local but = bill.TextButton
local door = game.Workspace.Bar.Door
local UseInputService = game:GetService("UserInputService")


UseInputService.InputBegan:Connect(function(input, gameproces)
	if not gameproces then
		if input.KeyCode == Enum.KeyCode.E then
			print("yoo")
			if (RHP.Position - door.Position).Magnitude < 15 then
				game.ReplicatedStorage.RemoteEvent.OpenDoor:FireServer()
				print("yoo")
			end
		end
	end
end)

any reply is appreciated!!

Instead of that, try local RHP = char:WaitForChild("HumanoidRootPart")

Also instead of that, try local char = player.Character or player.CharacterAdded:Wait()

1 Like

still not working but there aren’t any error

Wait its already working.I jst removed “WaitForChild()” .I’ll mark you as solution .thx for helping btw

I sometimes get this error when my character hasnt even loaded, but my player is already loaded

it can sometimes happen where the script runs before your character has loaded, thats why sometimes people use the player.CharacterAdded event to detect when their character has spawned/respawned