Attempt to index nil with 'position' on primary part, but It DOES exist

So I’ve got a script that automatically moves to a model’s Primary part, however, on specific models, the part will just stop at it instead of moving back where it came from like the script says, and in script output, it keeps showing " attempt to index nil with ‘position’. as if the primary part does not exist.

Things I’ve tried:
checking the models that the part moves to (they all have the same names and instances and such in them)
checking for primary parts (They ALL have one)
no scripts are affecting anything.

nothing on the dev forum shows anything similar. either

Until Then The part just stops moving every time and I cant figure out what is causing this.

any form of help is appreciated.

3 Likes

Are you perhaps moving the part as soon as the script starts? If so, you should yield the script until the model.PrimaryPart is not equal to nil, as it might have not loaded in yet. Please provide us with your script, though.

1 Like
  • Is it a local script or a server script?
  • Have you got StreamingEnabled turned on?

It’s possible that it just isn’t loaded in when you try to access it. Youll basically just have to wait until it’s loaded in if this is the case!

So this is hard to help you with. This likely depends very specifically on how your script is set up and we don’t have that or the explorer setup, so it’s all just guesses. The others have made a great suggestion about ensuring the primary part exists. But I want to add another suggestion. Make sure you are actually getting the model you think you are. A frequent issue people will hit is naming siblings the same name then trying to do something like workspace.npc. But if there are 2 things named workspace.npc then you effectively have grabbed a random one when you likely meant to reference a specific one.

idk this might fix

if you grab the primary part and set it as a variable just to make sure to primary part isn’t changed or something and you’re always working w the right part

e.g

local part = model.PrimaryPart

blah blah blah part

rather than

blah blah blah model.PrimaryPart

Possibly. I Used a similar copy of a script I already had, rewrote it, and it worked. I don’t exactly know what happened.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.