PrimaryPart property reads nil when running code instantly on client

print(workspace.Model.PrimaryPart)

23:33:58.485 nil - Client - LocalScript:1

If this is how Roblox works then I would like to know a workaround for this bug.

1 Like

When StreamingEnabled is turned on which is a property of Workspace, parts and instances in the world are dynamically streamed in and out based on the player’s proximity.

This means that not all instances in Workspace will be immediately available, which can cause the issue when you’re trying to directly access them.

To fix this, use WaitForChild() when referencing objects in Workspace to ensure the object has loaded.

2 Likes

Another tip on top of that. If you’re needing to bypass StreamingEnabled and have it loaded in on the client 24/7 you can set the ModelStreamingMode to Persistent.

And for whatever reason, if the model is just so HUGE!!! You can use workspace:WaitForChild(“Model,9999”). 9999 being the time, in seconds, until it eventually times out. Just remember it does yield the code so you can’t run anything else.

You do not need to specify a timeout to yield indefinitely, and it’s best if you avoid designing code that way if you’re working with streaming.

Rather than wait endlessly for the object to exist to execute, execute when the object is added, do this with ChildAdded/DescendantAdded/CollectionService/etc.

local primaryPartChangedSignal = workspace.Model:GetPropertyChangedSignal("PrimaryPart")
primaryPartChangedSignal:Connect(someFunction) --connect signal to function

:nerd_face:bah-rihhhhhhhhh I don’t think it matter that much for his use case.

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