v is model
also
v has primarypart
OK, just checking because I’d guess (with your earlier checks for waiting for character to load) that it’s not the humanoid.
But, easiest way to check is add some prints to debug it; put in
for i , v in pairs(doorparent:GetChildren())do
print(Character)
print(Character.HumanoidRootPart)
print(Character.HumanoidRootPart.Position)
print(v)
print(v.PrimaryPart)
print(v.PrimaryPart.Position)
if (Character.HumanoidRootPart.Position - v.PrimaryPart.Position).Magnitude < 5 then
Then look in the output. One of these somewhere will be nil, when you know which will help to track down the problem.
As you’ve waited for the character to load I’ll still guess it must be one of the different v’s that you are iterating through, but debugging would show if its that or not
(or put a breakpoint on and just check the values of things when it gets hit, either works)
print(v.PrimaryPart.Position)
this part saying nil. but I dont understand
What did the prints before that show, so before that printed nil what did print(v) output and what did print(v.PrimaryPart) output?
it did print except the last part
print(v) – print the name of the model
print(v.PrimaryPart.Position) – print nill
what did print(v.PrimaryPart) print out?
oops…silly me
print(v.PrimaryPart) – print nill
(v.PrimaryPart.Position) --print nothing
but when I clicked the error it show the (v.PrimaryPart.Position)
Yea I think that’s where it gives an error, cos you are trying to access .Position of something that’s nil there. And that’s what will break.
So should just need to set the primary part on the model and it’s all good.
but the model already has the primary part .I checked all of them
Hmm it can’t do if it says its nil here. I’m guessing there’s more than one model inside of game.Workspace.Door, as you’re looping through them
The name printed out by print(v) might help you to narrow down which one doesn’t have a primary part
So look in the out put for
print(v) → The model name
print(v.PrimaryPart) > nil
Then find the model with the name that was printed out just before this nil, and it should be that’s missing a primary part.
(I’m assuming here there’s no other scripts or anything running that would be changing these models or removing their primary part in any way)
it print this one name
DoorIdk
I already checked this model but there are nothing sus
Hmmm, so it prints out
print(v) > DoorIdk
print(v.PrimaryPart) > nil
print(v.PrimaryPart.Position) > errors here
And if you check that it’s all set up OK, so looks like
If that’s all ok before you press run, then also run your game. While it’s running, just after the error has happened, look in explorer and find the DoorIDK model again, is it still looking OK then? Does it still have its primary part?
When I click play…everything ok nothing seems changing only got an error and thats weird
So should I change Position to Origin Position instead??
This means that whatever you are taking the position of is nil. This meaning that the code cannot find either the PrimaryPart or the HumanoidRootPart that you are referencing.
No. If you screenshot your explorer I can take a look. I would also like the full script. I can solve this issue easily.
I experienced the same, Check if you are play testing your game that model still has a PrimaryPart. Probably not.
I made this workaround in my code
if yourModel.PrimaryPart == nil then
if yourModel:FindFirstChild("PK") then
yourModel.PrimaryPart = yourModel:FindFirstChild("PK")
end
end
if yourModel.PrimaryPart ~= nil then
primaryPart = yourModel.PrimaryPart;
end
-- do stuff with primaryPart
You might wonder what PK is? Well, its a CanCollideFalseInvisble1,1,1 brick which is welded to my model. It allows better precision if you have some kind of game where you can build stuff, Otherwise its a great workaround for this unreliable PrimaryPart.
You could also automate the PK if you are lazy with Instance.new
I gtg to sleep I’ll send u tomorrow
So as requested
so this is screenshot before I test the game
This is when I test the game
Is it some sort of bug??