How would i make this script give me a tool and put me a team

Hello ive got this script and I need to make it so there is one person who gets a tool from server storage then puts them in the team like green and white
The script is an intermission script.

local gMgr = {}
local sessionData = {}
local mSpawns = workspace.Map.Spawns:GetChildren()
local lSpawns = workspace.Lobby.Spawns:GetChildren()
local numOfPlayers = 0
local declareWinnerTime = 3
local rs = game:GetService("ReplicatedStorage")
local winnerRe = rs:WaitForChild("WinnerRe")
local intermissionRe = rs:WaitForChild("IntermissionRe")
local intermissionTime = 5

function gMgr:isEnoughPlayers()
	if numOfPlayers > 1 then
		return true
	end
	return false
end

function gMgr:declareWinner(player)
	-- remote event to UI
	winnerRe:FireAllClients(player, declareWinnerTime)
	wait(declareWinnerTime)
	sessionData[player]["isWinner"] = true
	sessionData[player]["wins"] = sessionData[player]["wins"] + 1
	for ply, data in pairs(sessionData) do
		local spawnPnt = lSpawns[math.random(1, #lSpawns)]
		ply.Character.HumanoidRootPart.CFrame = spawnPnt.CFrame + Vector3.new(0, 3, 0)
		data["isPlaying"] = false
	end
end

function gMgr:checkForLastPlayerStanding()
	local num = 0
	local aPlayer = nil
	for player, data in pairs(sessionData) do
		if data["isPlaying"] then
			num = num + 1
			aPlayer = player
		end
	end
	if num == 1 then
		return aPlayer
	end
	return nil
end
function gMgr:intermission()
	intermissionRe:FireAllClients(intermissionTime)
	wait(intermissionTime)
end

local function teleportPlayers()
	for ply, data in pairs(sessionData) do
		local spawnPnt = mSpawns[math.random(1, #mSpawns)]
		ply.Character.HumanoidRootPart.CFrame = spawnPnt.CFrame + Vector3.new(0, 3, 0)
		data["isWinner"] = false
		data["isPlaying"] = true 
	end
end

local function checkIfAnyoneIsPlaying()
	for ply, data in pairs(sessionData) do
		if data["isPlaying"] then
			return true
		end
	end
	return false
end

function gMgr:playGame()
	local stillPlaying = true
	teleportPlayers()
	while stillPlaying do
		stillPlaying = checkIfAnyoneIsPlaying()
		wait(1)
	end  
		
end

local function addChar(char)
	local player = game.Players:GetPlayerFromCharacter(char)
	sessionData[player]["isPlaying"] = false
end

local function addPlayer(player)
	sessionData[player] = { isPlaying=false, isWinner=false, wins=0 }
	numOfPlayers = numOfPlayers + 1
	player.CharacterAdded:Connect(addChar)
end

local function removePlayer(player)
	sessionData[player] = nil
	numOfPlayers = numOfPlayers - 1
end

game.Players.PlayerAdded:Connect(addPlayer)
game.Players.PlayerRemoving:Connect(removePlayer)

return gMgr

1 Like

Hi!

I’m not going to validate your code since that’s not the point here, but rather answer your question of “how” to give a specific player a tool and assign them to a team.

local ServerStorage = game:GetService("ServerStorage")
local ToolsStorage = ServerStorage:WaitForChild("Tools", 5) ---The folder that contains the tools.

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

---This function will give a tool to a player, it requires the player object and tool name.
function GiveToolToPlayer(player, toolName)
	local tool = ToolsStorage:FindFirstChild(toolName)

	if tool then
		local toolClone = tool:Clone()
		toolClone.Parent = player.Backpack
	else
		warn("Tool not found")
	end
end

---This function will assign a player to a team, it requires the player object and team name in string.
function AssignPlayerToTeam(player, teamName)
	local team = Teams:FindFirstChild(teamName)

	if team then
		player.TeamColor = team.TeamColor
	else
		warn("Team not found")
	end
end

GiveToolToPlayer(Players.PLAYER_NAME, "TOOL_NAME")
AssignPlayerToTeam(Players.PLAYER_NAME, "TEAM_NAME")
1 Like

Screen Shot 2023-02-06 at 10.40.17 am
Screen Shot 2023-02-06 at 10.39.23 am
Hello this didn’t seem to work i wanted the players like not a certain player sorry.

1 Like

Hi!

I am sorry but I don’t understand what you need. What are you trying to achieve exactly? Try to explain what you expect the code to do and I will see if I can help you out.

hi sorry i was trying to make a script that teleports players to a map and when they teleport there’s a one person with like a gun and the rest have to hide from that player but there in a different teams.