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

How Do I Make a Team Have a Limited Number Of Players?

Asked by 7 years ago

Hey, I'm making a game which has three teams, Mortals, Mortal Heroes, and Gods. I want to make it so that the Gods team can only have one player on it at a time and so that when the God dies he becomes a mortal (joins the Mortals team.) The Mortals and Mortal Heroes teams should not have a team limit and when they die they should stay on the same team, I just want these rules to apply to the one player on the Gods team. The team colors are Lapis for the Gods, Really Red for the Mortal Heroes, and New Yeller for the Mortals, in case you need any of that information to make this work. Could anyone help me figure out how to do this? Thanks, and comment below or message me on Roblox if you have any questions or if you need any more information to answer this. Thanks, Skyraider5

1 answer

Log in to vote
0
Answered by
fuj 49
7 years ago

Highly recommend you don't copy and paste, however I did put it into context for you. If you have any questions please reply and I will help asap.

local teamz = {
    ['God'] = 1,
    ['Normal'] = 16
}

local teams = game:GetService('Teams')
local gods = Instance.new('Team', teams)
local normal = Instance.new('Team', teams)
gods.Name = 'God'
gods.TeamColor = BrickColor.new('Bright Red')
normal.Name = 'Normal'

local function getamount(str)
    local amount = 0
    for k,v in next, game:GetService('Players'):GetPlayers()do
        if v.Team == teams[str] then
            amount = amount + 1
        end
    end
    return amount
end

game:GetService('Players').PlayerAdded:connect(function(p)
    p.Team = normal
    local lteam = p.Team
    p:GetPropertyChangedSignal('Team'):connect(function()
        table.foreach(teamz, function(a,b)
            print(p.Team == teams[a], getamount(a) - 1 < b)
            if p.Team == teams[a] and getamount(a) - 1 < b then
                print'you can change teams!'
                return
            elseif p.Team == teams[a] then
                print'sorry, this team is full!'
                p.Team = lteam
            end
        end)
    end)
end)
0
No, it's just the team limiter. fuj 49 — 7y
0
This wasn't the actual answer, it might work, but it doesn't with the way my game is set up I guess, but anyway I did figure out how to do it so this is technically answered just this answer wasn't it Skyraider5 -21 — 7y
Ad

Answer this question