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

How can I use MaxPlayers Value to do something a certain number of times?

So what I want to do is create a bunch of textbuttons on a surfacegui, but I need the textbuttons to equal the max players.

Here is what I have thought to do

for i=1,(game.Players.MaxPlayers) do
[Generate TextButton code is functional and would go here]
end

If this matters, this is going on a brick and will display the names of everyone who joins.

1 answer

What I would do, is use the PlayerAdded and PlayerRemoving events. Here's an example:

This code will print [Player's Name] Has joined the server when a new player is added and [Player Name] Has left the server When the player leaves:

game.Players.PlayerAdded:connect(function(player) -- Calls the player
print(player.Name.." Has Joined the Game")
end)

game.Players.PlayerRemoving:connect(function(player)
print(player.Name.." Has left the game.")
end)

So by using these events, you can easily:

Clone the GUI (When the player enters) Edit the GUI (You're choice how) Remove the GUI (by using :Destroy())

Hope I helped :D Feel free to PM me if you have any more trouble with this.

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