I am making a game that teleports players to a reserved server and I want the game to wait until all the players have loaded in how can I do this.
local count = 0
local required = --get the required amount of players. If i remember right, you can send an argument while teleporting to another place, you can use that argument
game.Players.PlayerAdded:Connect(function()
count += 1
if count >= required then
--start the game
end
end)
The comment section code depends entirely on the logic you already implemented, the above code is just to give you an idea.
How do I pass the data through, I am using TeleportToPrivateServer
TS:TeleportToPrivateServer(game.PlaceId,code,players) – Actually teleport the players
– You could add extra arguments to this function: spawnName, teleportData and customLoadingScreen
teleport data can be a number
local TeleportService = game:GetService(“TeleportService”)
local teleportData = TeleportService:GetLocalPlayerTeleportData()
https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportToPrivateServer
You can look at this thread for more info
Optionally, you can use datastore to save the playercount and load it in another place
If I understood you right, then that maybe work
while true do
wait()
for i, v in pairs(TeleportingPlayersNameTable) do
if game:GetService("Players"):FindFirstChild(v) then
repeat wait() until not game:GetService("Players"):FindFirstChild(v)
else
continue
end
end
break
end