Hello, I would like to know if a server has the maximum number of players allowed. For example if the server size is 2, when there are 2 players I trigger something.
But I don’t know how to know the server size in a script. If anyone has an answer, thank you.
You can simply create a variable to keep track of the number of Players in your server:
local Players = game:GetService(“Players”)
local playersinServer = #Players:GetPlayers()
if playersinServer > 1 then-- Change to your max server size
-- Code here.
end
local Players = game:GetService(“Players”)
local playersinServer = #Players:GetPlayers()
if playersinServer == Players.MaxPlayers then
-- do stuff
end
Players.MaxPlayers returns the maximum amount of players that can be in a server.
Just make sure to update the playersinServer variable whenever people are joining or leaving.
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
if #Players:GetChildren() > 1 then
--your function here
end
end)