Metatable printing as nil only when streaming is enabled and inside of the Roblox Player

Please note a local script is requiring the following module script, and therefore running locally.

Variable explanation:


rooms - A folder under a Module inside of the Workspace

rooms.Normal - Another folder

NatureTest - A model with its streaming mode set to persistent located under ‘rooms.Normal’. This is the only child under this folder.

self.Rooms = rooms:GetChildren()

waitroom - directly accessing ‘NatureTest’ through ‘rooms.Normal’

    local waitroom = nil
		waitroom = rooms.Normal:WaitForChild("NatureTest")
	until waitroom ~= nil
	print(waitroom) --prints 'NatureTest'
	printTable(self.Rooms) --does not print (used to decode memory address)
	print(self.Rooms[1]) --prints nil
	local newRoom = self.Rooms[random:NextInteger(1,#self.Rooms)]:Clone() --"attempt to index nil with 'clone'

The problem I am having with this is due to Streaming being enabled, and only inside of the Roblox Player, as when I am inside of studio, everything works fine. If I test through the roblox player however, the table ‘self.Rooms’ will print as nil, while ‘waitroom’ prints correctly. However, if I disable Streaming, everything prints normally and the script runs correctly. Any help is appreciated.

1 Like

With StreamingEnabled, roblox will remove anything outside its Maximum distance until you go back into said distance. This should not occur on the Server as this is only something the client does to save memory and improve efficiency, thus reducing lag.

Yes, I’m well aware of this. However, the model that I am attempting to clone, as I have stated in the very post above, has its property ‘ModelStreamingMode’ set to persistent, meaning that it would be loaded into the client no matter the distance. This is also not the issue as I am able to print the instance if I access it directly, rather than through the table. I’m sorry if I wasn’t clear about these things.

1 Like

I seem to have found A solution to this issue, in case anyone comes across this post with a similar issue. For some reason, the problem only occurs when the folder the script is attempting to make a table of is located underneath the workspace. By simply moving everything into replicated storage, the issue goes away. I do not know if this is a bug or something of that type, but I do not think this behavior is intended.

Hey there!

That would be because streaming only happens in Workepace, which is also something to keep in mind when considering which objects to copy via ReplicatedStorage and why (which ones don’t have to readily exist locally).

Instance straming usually takes slightly longer to make instances available. That includes attempting to send them over remotes from a server to a client. The time is not very predictable, so it’s safer to find alternative methods.

Since you’re cloning the rooms locally, ReplicatedStorage makes perfect sense.

In a hypothetical case In Workspace, a solid option would be to have a local list of map names to select from and only then use the selected name and WaitForChild() to access the model. In some cases building the list passively using a ChildAdded callback is not bad either.

1 Like

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