How can i make all player spawn at the same time, and not have to wait for others to load?

Sometimes a player does not get a loading screen, sometimes they just spawn, sometimes a player is still at the lobby when someone else has spawned in with the loading screen, idk how to fix this. I want everyone to get the spawn at the same time if possible.

for _, Player in pairs(game.Players:GetPlayers()) do
    		Player.Team = game.Teams.Runners
    		coroutine.wrap(function()
    		Player:LoadCharacter()
    		Player.CameraMode = Enum.CameraMode.LockFirstPerson
    		wait()
    	    if Player.Team == game.Teams.Runners then
    	    rE3:FireClient(Player) -- my loading screen
    	    end
    		Player.Character:FindFirstChild("Torso").CFrame = table.remove(AvailableSpawnPoints, math.random(#AvailableSpawnPoints)).CFrame + Vector3.new(0,10,0) 
    		end)()
    	end
1 Like

I mean looking at the code you provided by the look of it you do this one player at a time but I’ve also stated something to do with RespawnLocations which you might want to look into.

Just saying as a side note, its easier for you to code when you follow good practices such as proper indentation. Your code should be formatted like so, this way its easier for people like me to read:

for _, Player in pairs(game.Players:GetPlayers()) do
	Player.Team = game.Teams.Runners
	coroutine.wrap(function()
		Player:LoadCharacter()
		Player.CameraMode = Enum.CameraMode.LockFirstPerson
		wait()
		if Player.Team == game.Teams.Runners then
			rE3:FireClient(Player) -- my loading screen
		end
		Player.Character:FindFirstChild("Torso").CFrame = table.remove(AvailableSpawnPoints, math.random(#AvailableSpawnPoints)).CFrame + Vector3.new(0,10,0) 
	end)()
end

One work around is that:

What you could do is start with:

local players = game.Players:GetPlayers() -- This way we know what players were in the game at the start of the round in case another joins.

Instead of doing everything at once we can do everything one at a time - this would make our code slightly longer but its easier for us to code sometimes and the time scale wont change really. By saving the players at the start we could do for loops if we didn’t want to use coroutines - personally I have never felt a need to use one.

By looking at your code and the documentation I believe its because you have used coroutine.wrap() and you have to remember that wait() simply just says “let me move along to the next user” so players will be loaded when the server gets round to it and then it will go one by one firing the clients which may take time again. Not to mention you shouldn’t use “Player.Character:FindFirstChild(“Torso”)” followed by .CFrame as if it doesn’t find the Torso (not sure if I’m right so I might edit this realizing I’m wrong) it will flag an error. If you know the torso exists then simply do :WaitForChild(“Torso”, 5) the number saying how long we are willing to wait (5 seconds) and then you can act accordingly. That way I’m pretty sure if it doesn’t get what it wants then it just goes “i’m good thanks” and moves along.

Your ordering is a bit weird as well: Why not give them the loading screen GUI before messing with the teams and respawning all the players and sending them to the respective locations. Also to avoid using CFrame if you want you can do Player.RespawnLocation and manually assign where they spawn, that way you don’t have to CFrame move them - this way when you call Player:LoadCharacter() they go to the specific spawn pad which would mean everyone spawns at the same time.

Response bit, above is the reasoning:

  • Use Player.RespawnLocation instead of CFrame and then load the characters afterwards that way everyone spawns at the specific spawn pad at the right time.
  • Give players the loading screen before you respawn them all, that way they cant tell who’s loaded first.
  • You don’t need to complicate it with a coroutine if you don’t want to - that is my personal opinion but coroutines is basically just stopping you from calling the for loop again and again - to me I wouldn’t be bothered by this. I would only ever use a coroutine if I had to do loads of wait() statements.

If you need any help with the Player.RespawnLocation then send me a message (I’m using it in a universe system which doesn’t have teams - its pretty cool).

1 Like

I use CFrame becasue it causes the player to spawn on top of my map since its all indoors, and for some reason when i place the loading screen above loadcharacter() it does not run.

Place the spawn slightly lower then the floor, this can usually fix that issue. This usually applies when no super complex stuff is used in your maps (which is unlikely cause I doubt you’d mesh a building).

Not sure about the :LoadCharacter() thing and the loading screen. Do you mean the loading screen doesn’t run? If so that is just likely that the thing which controls the Loading Screen was reloaded (especially in StarterPlayerScripts) and as such when you do :FireClient() it eventually deletes that thread which was activated. If this isn’t the issue then please expand on the “does not run” thing so I can try to help.

Yes that is possibly the exact issue i am having

Where have you placed the GUI, In the current PlayerGui or StarterGui? This will make you slightly annoyed when you realise this but you can turn off ResetOnSpawn (LOL) and that way the GUI is still there.
image

I didn’t realise this myself for a while haha.

1 Like

Oh yea that fix the problem of it going away everytime, thanks

Alright, is the spawn thing working now or are you still having some trouble?

If it is then just mark it as the solution so people don’t continue trying to solve the issue :slight_smile:

If not then feel free to fire any questions or issues and I’ll see what advice I can give you, I find spawn locations always worked best (as they can be enabled and disabled and loads of other things) but if your intent on using CFrame then ways to speed up the time difference:

  • Have the values ready before hand, use the loading screen as much as you can to make the process seem smooth. The thing is when you call:
Player.Character:FindFirstChild("Torso").CFrame = table.remove(AvailableSpawnPoints, math.random(#AvailableSpawnPoints)).CFrame + Vector3.new(0,10,0)

It is obviously a function and so obviously the system will take a moment to handle it depending on how the server is running. This is why the :LoadCharacter() method would be more beneficial as its a faster process. The thing above is calling data values and doing maths but that minut time difference can obviously be noticeable in series. That 0.1 second delay each time ran lets say 30 times amounts to 3 seconds delay from the start to end - which can be a bit ehh, then not to mention the server has to CFrame a person.

Hopefully it all works now :pray: