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

Empty player teams?

How do i make a script that checks for an Empty player team. Like let's say there's one 4 people on one time which is red team and 0 players on the blue team. How can i let the script know that there's no players on the blue team

Here's what i got

if game.Teams.Freak == 0 then
	--code
end

1 answer

✓ Accepted answer

Ok, so I've written a 'lil something for ya.

Here is a function that'll check if a team has no players!

local redteam = game.Teams.Red
local blueteam = game.Teams.Blue

function checkbalance()
	local getredteam = getPlayers(redteam)
	local getblueteam = getPlayers(blueteam)
	if getredteam[1] == nil then
			print("Red has no players!")-- Event when red team has no peeps
		elseif getblueteam[1] == nil then
			print("Blue has no players!")-- Event when blue team has no peeps
		else
			print("There are still players on each team!")
	end
end

function getPlayers(team)
    local players = {}
    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        if player.TeamColor == team.TeamColor and not player.Neutral then
            table.insert(players, player)
        end
    end
    return players
end

checkbalance() -- call the function to see if any teams have 0 players

Call the checkbalance() function to check for no players on a team.

Hope this helps!

1 comment

0

I'm not understanding the "getPlayers" part. It prints that is a nil value

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