Attempt to index nil with "Position" error

For some reason, I am still getting this error is there a problem anywhere?



primary3

Did you try the vector3.new??

Vector3.new()

Where should I add it into script?

This happens either because PrimaryPart doesn’t exist when the script starts executing, or because the script confuses your Model.PrimaryPart object with the Model.PrimaryPart property. Generally it’s not a good idea to give objects property names. Although to reference the object itself you can use :FindFirstChild() or :WaitForChild():

local PrimaryPart = Door:WaitForChild("PrimaryPart") --actually waiting for the part to be added
1 Like

I am not sure… what is the script supposed to do??

Open the door, but currently just enable the Billboard GUI when close to the door.

I am confused because the same script worked today morning?

PrimaryPart is an attribute of the model. When you type Door.PrimaryPart you are actually getting a value from that attribute, rather than the PrimaryPart child.
You can either set the PrimaryPart in the model (preffered), change the name of the PrimaryPart element or use `Door:FindFirstChild(“PrimaryPart”).
primaryPart

1 Like

Then idk what is wrong with the script.

@Sleazel doesn’t he need to access the Character, not the Player?
If I remember correctly then when the Player is referenced it’s trying to get the ‘container’ that is the Player, but not the actual character in the workspace.

From what I can read in the script. The idea is that when a player gets close to the door, a gui or toggle appears (Press E) and then when the player presses such key, the door opens. Correct?

If so, why not use ProximityPrompt. It does exactly that, and can be calibrated to be instantaneous. Also saving you a lot of pains and time in scripting.

It must be my own GUI, it’s also for someone and he is requiring it.

1 Like

It appears you want players to be able to press E to open a nearby door. No need for all this networking and expensive render stepped events just use the new ProximityPrompt | Roblox Creator Documentation object. Its also much easier to make it compatible with more devices

If your choosing not to use it because it doesnt fit the style of your game you can hide the GUI and then make your own (if you wish to do so) by setting the Style property to Enum.ProximityPromptStyle.Custom

I never used it, but DistanceFromCharacter() is a player function. It should work. Getting
position from incorrectly referenced part is what is causing errors here.

But the problem is that DistanceFromCharacter doesnt work.

Was this reply meant for @Sleazel ?

I mean, I just want to use my own system. That’s all.

I am confused. Have you fixed your code at line 8?

local DoorPrimaryPart = Door:FindFirstChild("PrimaryPart")
1 Like

Reset the site, and see. Solved by you, thank you very much.