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

How to make a team chooser?

Asked by 10 years ago

I am making a game where the players can pick their teams, but theres a problem. All the players can just go on one team. What can I do to make the teams even and stop everyone from just joining one team.

local function countTeams( player )

    local rteam = 0
    local bteam = 0
    local neutral = 0

    for k,v in pairs(game.Players:GetChildren()) do

        if v ~= player then

            if v.Neutral then
                neutral = neutral + 1

            elseif v.TeamColor == teamRed then
                rteam = rteam + 1

            elseif v.TeamColor == teamBlue then
                bteam = bteam + 1

            else
                neutral = neutral + 1

            end
        end
    end

    return rteam, bteam, neutral

end
0
Why the hell did people rate this down, what a holes NinjoOnline 1146 — 10y

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

Divide the number of players in the game by the number of teams and round up. Make sure that if there are that many players on one team, you can't join that team unless someone leaves it.

0
????? NinjoOnline 1146 — 10y
1
Clearly something is wrong with you? 1waffle1 2908 — 10y
0
How, I am not the best scripter man, what you said is pretty jiberish in scripting, i used a free model for my question NinjoOnline 1146 — 9y
Ad

Answer this question