So pretty much when my game first boots up I copy a map from server storage with a folder called “Map” and then parent it to the workspace.
I then have some assets on the map that are tagged with collection service that I used GetTagged() to get. If I use GetTagged right after parenting the map could I face an issue where it doesn’t register certain assets because the map is still loading? And if so how can I yield for the entire map to load before calling GetTagged?
This is all done on the server for context. Hopefully I explained it well enough.
When loading maps (cloning them from ServerStorage to workspace) I like to load them by “chunks”, cloning and parenting a group of models per iteration of a loop that task.wait() in order to avoid that feeling of having a “minisecond of lag”, and adding a loading progress bar so the players can see that the map is loading.
Thats useful too so the functions, events connections etc that should run per map, finding objects to connect them/use them for something, Will wait until the whole map is loaded. After the map loading is finished it will just call a “startFunction” to connect map mechanics etc.
So you could iterate the folder of your map and clone the models/parts etc by groups, iterating them, cloning and parenting them using task.wait() or any other way you prefer that can yield the logic in your script
local CollectionService = game:GetService("CollectionService")
local ServerStorage = game:GetService("ServerStorage")
local expectedNumberOfAssets = 10 -- Set to the number of expected assets
local map = ServerStorage:FindFirstChild("Map")
if map then
map = map:Clone()
map.Parent = game.Workspace
else
warn("Map not found in ServerStorage!")
end
local function areAllAssetsLoaded()
local taggedAssets = CollectionService:GetTagged("YourTagName")
return #taggedAssets >= expectedNumberOfAssets
end
repeat wait(0.1) until areAllAssetsLoaded()
local assets = CollectionService:GetTagged("YourTagName")
-- Logic to proceed with once all assets are confirmed loaded