Waiting for all players to have loaded into the game (so they actually see the game and aren't stuck on the loading screen)

Hey! I’ve been trying to make a system that waits for all players to load into the game, and then resumes. With loaded, I mean they’re off the Roblox loading screen and can see the game world.

My current solution works fine in studio but then breaks in the Roblox player if you load for quite a while.

ReplicatedFirst local script:

local assets = {
	game:GetService("StarterPlayer"),
	game:GetService("ReplicatedStorage"),
}

for i = 1, #assets do
	game:GetService("ContentProvider"):PreloadAsync({ assets[i] })
end

game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("PlayerLoaded"):FireServer()

Script in ServerScriptService:

while #players:GetPlayers() < 1 do wait() end
local Loaded = 0
local MinimumLoad = #players:GetPlayers()

local timeout = 60 -- Change this to how many seconds until loading is made complete regardless of wether or not everyone has loaded.

game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("PlayerLoaded").OnServerEvent:Connect(function(p)
	Loaded = Loaded + 1
end)
local start = tick()

while Loaded < MinimumLoad and (tick() - start) < timeout do wait() end
warn("Finished waiting for players!")

(notable is that there’s another repeat until loop before above)

The other post’s I’ve found didn’t really help me so that’s why I’m here.

You can use game:IsLoaded() and a remote event to check if all players are loaded or not.

Aha. But doesn’t game:IsLoaded() only work on the server? Or does it work on the client as well?

It works on the client and the server. I always use this to make sure the user/server has loaded:

local GameLoaded = game:IsLoaded() or game.Loaded:Wait()
1 Like

Nope, it works on client as well.

1 Like

Like this?

local GameLoaded = game:IsLoaded() or game.Loaded:Wait()

game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("PlayerLoaded"):FireServer()

What ROBLOX says on the wiki:

if not game.IsLoaded() then
    game.Loaded:Wait()
end

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