Team Handler, a way to make teams without Team service!

What is Team Handler?

Team Handler is not one, but two, separate modules for either simplicity or more advanced needs. The main purpose of this is to work on team-based projects without using Roblox’s Team service. While Roblox’s Team service is all ready solid, sometimes it’s fun to make everything yourself to customise the functionality of it further. That, or you just don’t want team chat colours. (Which was my reason) So, what’s in the package? Well, I’ll get down to that.

If you’d rather explore it on your own right now, you may find the model here: https://www.roblox.com/library/5080202427/Team-Handler

Alternatively, you may download an example place here:
TeamHandler Example.rbxl (21.9 KB)


TeamHandler


TeamHandler is your basic happy-go-lucky module which has VERY basic functionality for simplicity. Super simple to set up and easy to work with. Each player will only be allowed one team assigned and it automatically removes players from their current team if they join another.

Provided example:

local TeamHandler = require(script.Parent.TeamHandler);
local TeamsToInit = {"Red", "Blue", "Green", "Lobby"};

for _, Team in pairs(TeamsToInit) do
	TeamHandler.AddTeam(Team);
end

game.Players.PlayerAdded:Connect(function(Player)
	TeamHandler:AddMember("Lobby", Player);
	
	print(TeamHandler:CheckForTeamMember("Lobby", Player)); -- returns true
	
	TeamHandler:AddMember("Blue", Player);
	
	print(TeamHandler:CheckForMember(Player)); -- returns the team of player, which is blue.

    for i, v in pairs(TeamHandler:GetAllTeamMembers("Blue")) do -- gets all players within a team.
        print(v);
    end
end)

game.Players.PlayerRemoving:Connect(function(Player)
	TeamHandler:RemoveMember(Player); -- removes it automatically.
-- OR OPTIONALLY: TeamHandler:RemoveMember(Player, "Blue"); -- implying you know which team they're in.
end)

Additionally, every player added to a team is given a tag with CollectionService. Use this as you will.


ClassTeamHandler


ClassTeamHandler utilises a faux class using an Object Orientated Programming style with larger customisation such as team colours, team spawns and tools. This one is paired best with other OOP work. This one allows for players to join more than one team, which is an optional feature.

Supports:

  • Team Colours (no real purpose unless you set it up yourself)
  • Team spawns
  • Team tools
  • Forcefield on team spawn

Provided example:

local TeamHandler = require(script.Parent.ClassTeamHandler);
local TeamsToInit = {"Red", "Blue", "Green", "Lobby"};

local Teams = {};

for _, Team in pairs(TeamsToInit) do
	Teams[Team] = TeamHandler.new(Team);
end

Teams["Green"]:SetSpawns({workspace.GreenSpawn}) -- example utilises a table of desired parts which are the desired spawn locations of a set team.
Teams["Green"]:SetTeamSpawn(true); -- allows team spawning.

game.Players.PlayerAdded:Connect(function(Player)
	Teams["Green"]:AddMember(Player);
	Player.CharacterAdded:Wait();
	
	Teams["Green"]:SpawnTeamMember(Player); -- spawns player at a random location within the set team spawns. should be used with characterautoload disabled.
	
	wait(10);
	
	TeamHandler:RemoveTeam("Green"); --event within the module which allows you to remove teams which are no longer needed.
	Teams["Green"] = nil; -- please destroy any external references to team objects after removing them to clean up memory!
	
	print(TeamHandler.Teams["Green"]); -- prints nil, meaning the team no longer exists within the module, internally.
end)

game.Players.PlayerRemoving:Connect(function(Player)
	local Team = TeamHandler:FindTeamMember(Player);
	
	if Teams[Team] then
		Teams[Team]:RemoveMember(Player); -- must be done for memory purposes.
	end
end)

If you wish to access teams from other scripts, all you have to do is require the module and do the following:

-- Script 1
local TeamHandler = require(script.Parent.ClassTeamHandler);
TeamHandler.new("Green");

-- Script 2
local TeamHandler = require(script.Parent.ClassTeamHandler);
local GreenTeam = TeamHandler.Teams["Green"];

Like before, every team member is given a tag with CollectionService using the team’s name. Do so as you wish with this.


Outro and misc.

This is a light addition and you shouldn’t expect the modules to do all the leg work for you, but they’re there to aid with team creation with some basic functionality. You are also welcome to expand upon the modules and add, remove or change how it might function to cater to your needs.

If you have any feature requests and feedback, please leave a response!

13 Likes

It may have been more logical just to fork the chat then to remake teams… XD

Just a question since it didn’t seem obvious, are there any actual extra functionalities to using this over team service?

2 Likes

Suppose so, but to each their own.

Yes and no. I’d say it depends on how you put it to use. It functions more or less as the same as the Team service, but expandability and customisability is in mind. Team tools, which isn’t an actual Team service feature, is built-in into the ClassTeamHandler. With the same concept in mind, you could apply it to anything else to make it team-based.

1 Like

I might use this for minigames. I have a game where up to 6 different minigames can run at once, and this might be useful.

Perfect! This is very useful thank you :smiley:

Can players be in several “teams” at once?
Maybe you have a Lobby and Playing team but would also like to split everyone between Males and Females (just an example).

The ClassTeamHandler supports multiple teams at once, the basic one does not in attempt to keep it simple.