Hi. I was wondering how I would make a GUI button that would change teams ,but if the team has like 3 players in it they can't join.
✓ ANSWER ACCEPTED
I need help with a max player system for teams?
1 answer
✓ Accepted answer
Okay, first, make a RemoteEvent called TeamChange and put it into ReplicatedStorage. Next, make your Team(s) and put them into game > Teams. Then, insert a LocalScript into your TextButton and type this:
local btn = script.Parent
local event = game.ReplicatedStorage.Events.TeamChange
local maxPlayers = 3
local team = game.Teams.Team --Team name
btn.MouseButton1Click:Connect(function()
local plrsInTeam = team:GetPlayers()
if #plrsInTeam < maxPlayers then
event:FireServer("Team Name")
else
btn.Text = "Team Full!"
wait(1.5)
btn.Text = "Team Name"
end
end)
Do the same for other text buttons that change teams. After that, insert a script into ServerScriptService and type this:
local event = game.ReplicatedStorage.Events.TeamChange
local team1 = game.Teams.Red
local team2 = game.Teams.Blue
event.OnServerEvent:Connect(function(plr, team)
if team == "Team1 Name" then
plr.Team = team1
elseif team == "Team2 Name" then
plr.Team = team2
end
end)
If you want more teams just copy the
elseif team == "Team2 Name" then
plr.Team = team2
part and change the team name. If you're having trouble, I made a model to help out: https://web.roblox.com/library/4467443496/Team-Change-Gui Hope this helps!
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Thx man
Yep