Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Game count not working?

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


2 answers

✓ Accepted answer

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.

2 comments

0

Yeah, but i'm mainly trying to test my scripting ability and trying to learn more by trying to get this to work

0

k

This discussion is preserved as it was. New answers, comments, and votes are closed.