Coding Teams Problem

Hey, I’m coding a /jointeam command, for a specific team I want it to check if someone is already on that team and if there is someone on that team, I want it to do something else. How would I do this?

If you mean if ANY player is on a team.

if #team:GetPlayers() == 0 then
	-- empty
else
	-- at least one player
end

If you mean if that specific player is on the team, just check their team property.

5 Likes

That’s actually really simple.

--you want to define the team, just to make it easier.
local team = game:GetService("Teams").Robbers --for example.
--next the if statement
if #team:GetPlayers() == 0 then
    print("No one is on the team Robbers.  Checking for empty server...")
    wait(.25)
    if #game.Teams.Cops. == 0 then
        print("Empty server, verified.")
    else
        print("Not an empty server.")
    end
else
    print("Robbers has a number of players, number is currently "..#team:GetPlayers())
end

--I went a bit overboard, I will admit, but I wanted to show you the capabilities of this.

--[[
EXPLAINING!
What this does is basically checks if the team is empty or not.  If it is, it will tell you whether it's a fresh server or not.  This can help debug, if you want to know when a bug is primarily active.

Sorry if I went over the limits of what you wanted, I just wanted to tell you what this really does, so you can really get it into your head.
]]--

Hope this helped!

3 Likes