How Do I Wait for Every Player to Load The Map?

At first I tried moving it from ServerStorage to workspace, and then ReplicatedStorage. But neither worked and some players still would spawn under the map. Now I’m using this script:

local totalParts = 0
local function LoadMap(prt, parent)
	if prt:IsA("Model") then
		if #prt:GetChildren() > 0 then
			print("Model:", prt.Name, "Children:", #prt:GetChildren())
			local newModel = Instance.new("Model")
			newModel.Name = "Game_Map"
			newModel.Parent = parent
			local searched = 0
			for _, prtChild in pairs(prt:GetChildren()) do
				totalParts = totalParts+1
				if searched % 300 == 0 then wait() end searched = searched + 1
				LoadMap(prtChild, newModel)
			end
		end
	else
		prt:Clone().Parent = parent
		print("Cloned:", parent.Name)
	end
end

To load it in piece by piece, I then follow it up with a wait of 4 seconds just to be safe. (The above code wasn’t made by me.) However although it is MUCH rarer, some players still have issues when it comes to spawning under the map. How can I make sure this NEVER happens?

2 Likes

what do you mean by players get spawned under the map?

What seems to happen is players don’t load in the map properly on their device, or load it in too late-- and it results in them spawning under the map while everyone else is in the map. I’m not entirely sure that is myself all I know is that it happens, and it’s not an issue with how I teleport them.

do you move it from a server script or local script?

Why not a have a remote event and make it fire to all clients, and then on the client move the model from replicated storage to the workspace, then move the player to the map.

You know, you could just not do this and instead clone the entire map from a storage service, then move it into the workspace. Why are you “loading” piece-by-piece?

Because when I cloned it, players still managed to spawn outside of the map. This way does take longer but it gives the players more time to properly load in the map.

When the players spawn outside the map, is the map loaded in fully? Or is it still loading when the players spawn outside the map?

If the map is still loading in when the player spawns that means the maps assets are taking longer to replicate to the client, assuming the map is placed within ServerStorage. To fix this you should consider placing the map in ReploicatedStorgae because this way, when the player first joins the game the map is replicated to the client ready. In other words the map is loaded onto the client when they first join the game.

I don’t know what your game is about but I am fairly certain your game is a round based game of some kind. If this is the case you may have an intermission stage where players have to wait for the next round to start. Why don’t you start loading the next map as soon as the intermission starts as this could give you 30 or so more seconds for the map to properly load in.

3 Likes

have you concidered moving the players to a spawn brick in the map with cframe? (or a bunch of spawn bricks and randomize it)

for i,v in pairs(game.Players:GetPlayers()) do
    if v.Character then
        v.Character.HumanoidRootPart.CFrame = SpawnBrick.CFrame + Vector3.new(0,3,0)
    end
end

preventing them from spawning under the map

Why don’t you put the Baseplate inside Workspace from the Start and then move everything else into Workspace afterwards so the Players won’t fall under it.

First off, don’t use wait() use a faster version such as .Stepped:Wait(), otherwise you’re going to encounter much longer wait times per part than expected.

But as others have mentioned, there is no reason players would spawn under the map no matter what timing if you clone the map from the workspace. A much better method would just be using:

  • Clone map to workspace from ServerStorage
  • FireAllClients to CFrame their HumanoidRootPart to the required spawn location or do it from the server script, up to you
  • Profit

Just sync them… not harder than that.

Thank you all for your replies! I’ve tried putting the maps in both ServerStorage and ReplicatedStorage. Both yield the same results where a majority of players spawn normally, but the odd few (presumably the ones with not as good internet, or so it seems) don’t load the map in time and fall out. I think I’m going to try @waterrunner’s method of loading the map during intermission. I’ve also added a failsafe so that if a player manages to get under the map, they’ll be teleported back up to the map or killed depending on if a round is in progress or not. The maps are currently in ReplicatedStorage, for anyone wondering.

4 Likes