I'm trying to make something so if too many people get on it shuts down the server, to test it I put it for 2 people.
local amount = 0 game.Players.PlayerAdded:connect(function(player) amount = amount + 1 print(amount) end) game.Players.PlayerRemoving:connect(function(player2) amount = amount - 1 print(amount) end) while true do if amount == 2 then Instance.new("Message",Workspace).Text = "Too many people... Shutting down server" wait(2) for i,v in pairs(game.Players:GetChildren()) do v:Remove() end end end
Why not use NumPlayers? Also, you need to change your Instance.new statement.
local TooManyPlayers = 2 while true do if game.Players.NumPlayers == TooManyPlayers then local Message = Instance.new("Message",Workspace) Message.Text = "Too many people... Shutting down server" wait(2) for i,v in pairs(game.Players:GetChildren()) do v:Kick() --Kick them instead! end end end
Just change the max players. If yo want only 6 people then change max players to 6.