How do I run a function only when the user is close to the door?

local Text = script.Parent
local MainGui = script.Parent.Parent
local EnterButton = MainGui.TextButton
local TextPrompt = MainGui.TextLabel
Text.PlaceholderText = “Create a Password”
EnterButton.Text = “Create!”
local PasswordDoor = game.Workspace:WaitForChild(“Model”)
local IsEntered = false
local DISTANCE_TO_DOOR = 10
local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()

local function isCloseEnoughToDoor(player, door)
–//Assign some random part in the door to be the PrimaryPart of the model
return (player.PrimaryPart.Position - door.Part.Position).Magnitude <= DISTANCE_TO_DOOR
end

if isCloseEnoughToDoor(Character, workspace.Model.Part) then
print(“HI”)
end

This is the error:

Players.TheFreeScriptDev.PlayerGui.PasswordGUI.InputDetector.LocalScript:14: attempt to index nil with ‘Position’

Very late reply!! its cause theres no such thing as a “primary part” of a player. Primary parts only exist in models. Use player.Character