Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Game count not working?

Asked by
dreamy67 135
10 years ago

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

Log in to vote
0
Answered by 10 years ago

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
Ad
Log in to vote
0
Answered by 10 years ago

Just change the max players. If yo want only 6 people then change max players to 6.

0
Yeah, but i'm mainly trying to test my scripting ability and trying to learn more by trying to get this to work dreamy67 135 — 10y
0
k EzraNehemiah_TF2 3552 — 10y

Answer this question