I want to achieve a script that has a variable that is the number of players in the server.
The issue is that if I print the variable, it just says 0.
I have tried switching between GetChildren() and GetPlayers().
This is the code:
local players = game:GetService("Players")
local count = #players:GetPlayers()
if count < 2 then
print("Not enough players to start the game.")
print(count)
end
Also this is my first topic so if I need to change anything just say.
for _, v in ipairs(game.Players:GetChildren()) do
print(v) -- print everything inside the players service
end
for _, v in ipairs(game.Players:GetPlayers()) do
print(v) -- will only print if a player object found
end
task.wait(5)
local players = game:GetService("Players")
local count = players:GetPlayers()
if #count < 2 then
print("Not enough players to start the game.")
print(#count)
else
print("Enough players to start the game!")
print(#count)
end
Not sure if this will help you. But you can try. It waits .1 seconds until the “:GetPlayers()” is higer or equal to the “Required” value
local Required = 1
local players = game:GetService("Players")
repeat task.wait(.1) until #players:GetPlayers() >= Required
local count = #players:GetPlayers()
if count < 2 then
print("Not enough players to start the game.")
print(count)
end