Hello,
i want to make a script, that waits, until every player is loaded in. Here is my code:
local num = 0
game.Players.PlayerAdded:Connect(function(plr)
for i, player in pairs(game.Players:GetPlayers()) do
print(i)
repeat wait() until
game.Workspace:FindFirstChild(plr.Name)
if game.Workspace:FindFirstChild(plr.Name) then
num = num + 1
print(num)
if num == i then
player.PlayerGui.Loading.Enabled = false
end
end
repeat wait() until
num == i
end
end)
This script only works, when there is only one player who loads in.
I hope someone can help me
~ maini
I have an idea, make a local script that detects when the player loads in and make a remote event to send it to a server script. the server script stores it in a table and check if the table equals the amount of players in the game (i hope you understand).
local loadedplayers = {}
function Check(player)
if loadedplayers[player.Name] ~= nil then
if loadedplayers[player.Name].PlayerGui:WaitForChild("Loading") then
loadedplayers[player.Name].PlayerGui.Loading.Enabled = false
end
end
end
game.Players.PlayerAdded:Connect(function(player)
if player ~= nil then
local character = player.Character or player.CharacterAdded:Wait()
if character ~= nil then
loadedplayers[player.Name] = player
Check(player)
end
end
end)
print(loadedplayers)