Team only group rank tool

Is there a way to turn this into team only too? i have been using this script but having to delete tools in other teams has been very stressful and not reliable.

local Players = game:GetService("Players")
local GrpId = 0-- You change this

local Items = {
	["M9B"] = game.ServerStorage["M9 Beretta"],
	["BTN"] = game.ServerStorage["Baston"],
	["RAD"] = game.ServerStorage["Radio"],
	["DTN"] = game.ServerStorage["Detain"],
	["CUF"] = game.ServerStorage["Cuffs [PC]"],
	["LMT"] = game.ServerStorage["LMT Defender"],
}

local RankItems = {
	[12] = {"M9B", "BTN", "RAD"}, 
	[13] = {"M9B", "BTN", "RAD"},
	[14] = {"M9B", "BTN", "RAD"},
	[15] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[16] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[17] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[18] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[19] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"}, 
	[20] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[21] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[22] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[23] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[24] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[25] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[50] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[70] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[100] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
	[150] = {"M9B", "BTN", "RAD","CUF","DTN","LMT"},
}

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		local GroupRank = Player:GetRankInGroup(GrpId)
		if RankItems[GroupRank] then
			for _, item in pairs(RankItems[GroupRank]) do
				Items[item]:Clone().Parent = Player.Backpack
			end
		end
	end)
end) -- credits to the guy who made this one!

You can use;

if Player.Team == game.Teams[teamName] then

to check the player’s team, so you can add that if statement within the characteradded function.

i don’t understand that much on scripting could you explain more?

Try this:

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function()
		local GroupRank = Player:GetRankInGroup(GrpId)
        print(GroupRank)
		if RankItems[GroupRank] then
			for GroupNum, Item in ipairs(RankItems) do
				GroupNum[Item]:Clone().Parent = Player.Backpack
			end
		end
	end)
end) -- credits to the guy who made this one!

I believe you could just check the index for the dictionary instead