So I found out LoadCharacter yields on R15, how do you respawn everyone quickly on a round end if LoadCharacter yields? It causes a delay after the round ends, instead of it ending smoothly.
Have you tried making a coroutine?
for _, player in pairs(Players:GetPlayers()) do
coroutine.wrap(player.LoadCharacter)(player)
end)
2 Likes
Yeah so what happens is the thread continues, ending the round, before characters respawn.
2 Likes
So you want to load all characters in at the same time, but yield until they’re all spawned?
local thisThread = coroutine.running()
local players = Players:GetPlayers()
local playersLeft = #players
local function spawnCharacter(player)
player:LoadCharacter()
playersLeft = playersLeft - 1
if playersLeft == 0 then
coroutine.resume(thisThread)
end
end
for _, player in pairs(players) do
coroutine.wrap(spawnCharacter)(player)
end
coroutine.yield()
Note there’s more nuance you’ll need like a player leaving while this happens, but you should get the gist.
1 Like
This may explain why my game delays for a while when respawn players…