How would I do this?

Could some explain how I would do this:

There are 16 teams, and you can’t join more than one at once.
I want the data of each team(the players in the team) to save so I can check how much people are in a team and make a list of the players

How would I go around doing this?

Make a team selection system parts.or GUI:

script.Parent.Touched:Connect(function(part)
  game.Players:GetPlayerFromCharacter(part.parent).Team = game.Teams.Red
end)

And when the player leaves update a data store.

Right but you can’t save tables so how would I do this

I believe you can save tables. Or just make a counter and update it every time.(It’s kinda inefficient)
Or convert the table to a string and use pairs to make string to table

And the data store would be like:
TeamRed
{
ListOfPlayers,…
}
TeamBlue
{
…
}

you can make module script somewhere

local Teams = {
	Red = {},
	Blue = {},
	Green = {}
}

return Teams

when someone joins the team just add them into the team table!
to get table just simply do in your script

local Teams = require(game.ReplicatedStorage:WaitForChild("TeamsList")) -- Example path
print(Teams) -- TABLE WITH EVERY TEAM
print(Teams.Red) -- Everyone in red team
-- or 
print(Teams["Red"]) -- Everyone in red team
-- then if you want to get everyone in red team:
for index, player in pairs(Teams["Red"]) do
	print(player) 
end

-- to get number of players in team:
print(#Teams["Red"]) -- Should work fine

Alright so I have a folder with all the teams with the amount of players in the team.

I’ll probably save the players later but for now I want to save the amount of players in a team.

Like I said a folder of all the teams and the int value amount is made by the server, but how would I save the data in that.

Its hard for me to help you right now, it will be easier if you send a screenshot of it, and also tell me you want to save int value about max players per team or just how much people currently are in the team?

I want to save how much players are in the team.

You can do smth like so:

Get the amount of players in the team

local amount = #teamFolder:GetChildren()

Then you save it by simply saving that number, the way you do it depends on exactly what youre doing. If youre using a global datastore or what. But i would also add a folder.ChildAdded function that adds refreshes the amount

teamFolder.ChildAdded:Connect(function()
amount = #teamFolder:GetChildren()
end)

I hope this helps at least somewhat :slight_smile:

Thing is the amount of players is just an int value, how would I go round saving all these int values in these folders?

okay, to get current players in team, tell me how you want to store player data? you can create for every player another value like ObjectValue with player character stored or using ModuleScript with table that contains everyone, you can also use roblox teams system
image
soo tell me how you want to make this?

Example using ModuleScript:
Module:

local Teams = {
	Red = {},
	Blue = {},
	Green = {}
}
return Teams

normal script:

local Teams = require(game.ReplicatedStorage:WaitForChild("TeamsList")) -- Example path

-- Example usage:
-- Make event on click join and then:
local JoiningTeam = "Red" -- Team that player is joining
if #Teams[JoiningTeam] and #Teams[JoiningTeam] < 5 then -- 5 is max players in team
	table.insert(Teams[JoiningTeam], Player)
end

-- If you want to get how much players are in current team then:
print(#Teams["Red"]) -- # symbol is for getting length of table

but remember to make RemoteFunction or RemoteEvent when player is clicking Join button soo Server will check all that instead of client

Ok, you could probably just loop through all the folders, assuming they all have identical intvalues, and then save the numbers under the teams name.

local Table = {}

for _, teams in pairs(TeamsFolder:GetChildren()) do
if teams:IsA(“Folder”) then
local value = teams.IntValue
table.insert(Table, {
teamName = teams.Name,
TeamValue = value.Value
}
end
end)

Smth like that should work, then use setAsync, or updateAsync if its global datastore, in order to save the values in the table. (Make sure to put “return Table” at the end of your saving function)

Rn I want to save int values that are in every team’s folder.

yes, if you want to store instantly every team, you can first list your teams folder, get each name of the folder and store names into a table

local Teams = {}

for _, Team in pairs(game.ReplicatedStorage:WaitForChild("Teams")) do
	if Team:IsA("Folder") and not Teams[Team.Name] then
		Teams[Team.Name] = {}
	end
end

return Teams

then you will only need to add player into the table for each Team

1 Like

save where? i still dont know what you want to achive, i asume that you want to have data about players in teams and also know how much players are in the team, im trying you help you by using the easiest and the best solution by making ModuleScript that you will call TeamData for example, in there you will have data about players in teams, you can even store there later MaxTeamLimit value, team score and other stuff, but currently you want it just to store players that are in each team

I want to use the team folder and save everything in that folder.

The amount of players and an object value or string value that leads to the player.

So basically, everything in all the team folders should be saved.

soo you want to save everything visually not in table inside module script, right?
Player names, Player current count, everything?
tell me yes and i will make some simple script for you with comments soo you will understand

Yeah, I realized it can save tables but not dictionaries so yes I want to save everything visually(in the folder)

okay, i made some scripts for you, but you will need to change everything for your needs, also i suggest to make new folder inside each team with name “Players” or something like that soo it will be easier for you to make later more information for each team such as “Team score”, “Team limit” and other!

Server script located at “game.ServerScriptStorage”:

local JoinTeamRemoteFunction = game.ReplicatedStorage:WaitForChild("JoinTeamRemoteFunction")
local TeamsFolder = game.ReplicatedStorage:WaitForChild("Teams")

function CheckIfAlreadyInTeam(Player)
	for _, Team in pairs(TeamsFolder:GetChildren()) do
		local PlayerInTeam = Team:FindFirstChild(Player.Name) -- FIND PLAYER NAME IN TEAM FOLDER
		
		if PlayerInTeam and PlayerInTeam:IsA("ObjectValue") then -- IF PLAYER IS IN A TEAM AND ITS A OBJECTVALUE RETURN TRUE
			return true
		end
	end
	return false -- IF PLAYER IS NOT IN A TEAM RETURN FALSE
end

JoinTeamRemoteFunction.OnServerInvoke = function(Player, TeamName)
	if TeamsFolder and TeamsFolder:FindFirstChild(TeamName) then
		local Team = TeamsFolder[TeamName]
		
		-- I KNOW THAT THERE IS A DOUBLE CHECK BUT FIRST CHECK IS FOR EVERY TEAM AND THE SECOND IS ONLY FOR ONE TEAM
		
		if not CheckIfAlreadyInTeam(Player) then -- IF PLAYER IS NOT IN ANY TEAM YET
			if Team and not Team:FindFirstChild(Player.Name) then -- If Team is inside of Teams folder and player is not already in this team then
				local NewPlayerObjectValue = Instance.new("ObjectValue")
				NewPlayerObjectValue.Value = Player -- SET OBJECT VALUE TO PLAYER (game.Players.PLAYERNAME)
				NewPlayerObjectValue.Name = Player.Name -- CHANGE NAME TO PLAYER NAME
				NewPlayerObjectValue.Parent = Team -- PUT PLAYER IN A TEAM
			end
		end
	end
end

Local script inside button:

local JoinTeamRemote = game.ReplicatedStorage:WaitForChild("JoinTeamRemoteFunction")
script.Parent.MouseButton1Click:Connect(function()
	JoinTeamRemote:InvokeServer("Ajax")
end)

and also you will need to make RemoteFunction at ReplicatedStorage
image
and as i click join on Barcelona team, i got a value inside the folder:

also you need to make later event that checks if player has left the game and removes him from teams folder

1 Like

I’m unable to help you to fix the issue, but I do recommend switching the names to something similar, since your game might be taken down because of copyright. You could switch a team like Ajax to Abax or something like that, similar to how Super League Soccer changed Al-Nassr to Yellow Riyadh

1 Like