-
What do you want to achieve? Keep it simple and clear!
I want to make a script that can check if all players have loaded/joined the game. -
What is the issue? Include screenshots / videos if possible!
I have tried everything, nothing works. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried Devfourm and YouTube.
I would wait for all the player’s characters to load and add them all to a table, then check if that table has all the players in it.
Edit: Could you provide more detail so I can write you a script for it?
I’m not sure if this is what you needed but here’s a Script that does all that.
-- Where you start (lobby) -- Script
local teleportService = game:GetService("TeleportService")
local placeId = 0 -- Change this to your destination's placeId
-- local placeId = teleportService:ReserveServer(placeId)
local players = {}
local nPlayers = 0
nPlayers = table.getn(players)
for index, player in players do
teleportService:Teleport(placeId, player, nPlayers)
end
-- Where you end (second place) -- LocalScript in StarerPlayerScripts
local teleportService = game:GetService("TeleportService")
local nPlayers = teleportService:GetLocalPlayerTeleportData()
game.ReplicatedStorage.ClientServerCommunication:FireServer(nPlayers)
-- Create a RemoteEvent in ReplicatedStorage named ClientServerCommunication
-- Where you end (second place) -- Script in ServerScriptService
local csc = game.ReplicatedStorage.ClientServerCommunication
local players = game.Players
local tempPlayers = 0
_G.nPlrs = 0
function loaded()
-- Run this when all players loaded
end
csc.OnServerEvent:Connect(function(plr, nPlayers)
_G.nPlrs = nPlayers
end)
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
tempPlayers = tempPlayers + 1
if tempPlayers == _G.nPlrs then
loaded()
end
end)
end)
You can modify this code and make it run the loaded function after 60 seconds even if not all the players loaded yet if you need to.
One way to check if all players have loaded/joined the game is to use a server script that keeps track of the number of players who have loaded/joined the game. You can use a combination of the PlayerAdded and PlayerRemoving events to keep track of the number of players who have loaded/joined the game.
Here’s an example script that prints a message when all players have loaded/joined the game:
local Players = game:GetService("Players")
local function CheckAllPlayersLoaded()
-- Get the number of players who have loaded/joined the game
local loadedPlayers = 0
for _, player in pairs(Players:GetPlayers()) do
if player:IsLoaded() then
loadedPlayers = loadedPlayers + 1
end
end
-- Check if all players have loaded/joined the game
if loadedPlayers == #Players:GetPlayers() then
print("All players have loaded/joined the game!")
end
end
-- Check if all players have loaded/joined the game when a player joins or leaves
Players.PlayerAdded:Connect(function(player)
CheckAllPlayersLoaded()
end)
Players.PlayerRemoving:Connect(function(player)
CheckAllPlayersLoaded()
end)
-- Check if all players have loaded/joined the game every 5 seconds
while true do
CheckAllPlayersLoaded()
wait(5)
end
You can adjust the time interval for checking if all players have loaded/joined the game by changing the wait time in the while loop.
There’s no function for the player called “IsLoaded()”. Only the game has it.
-- Player added event
game.Players.PlayerAdded:Connect(function(player: Player)
local loaded = player:HasAppearanceLoaded()
while not loaded do
loaded = player:HasAppearanceLoaded()
task.wait()
end
-- At this point you can do whatever you want with the player, now that it is verified that they have loaded
print(player.Name .. " has loaded.")
end)
UPDATE I gave up with this system but thanks everyone for the help!