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

I need help with a max player system for teams?

Asked by 4 years ago

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.

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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!

0
Thx man dogethefrog 12 — 4y
0
Yep QuantumPlasmic 84 — 4y
Ad

Answer this question