Team Only Gamepass Tools

Hi, I’m just trying to start scripting for a month or two.

I’ve been trying to make a script where if you own a certain gamepass, you will receive a tool but only for a certain team. I’ve tried scripting it on my own at first, but nothing worked, and after an hour or so of searching on the dev forum, there was no successful solution that I could find.

The team name that I’m trying to make it for is “CITIZEN” and the team color is “Camo”

My current script (similar to a post from 2021) is:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local GamepassID = 68207514
local Tools = {"M40A5"}
local ToolsParent = ReplicatedStorage.ACS_Engine.ToolStorage.Gamepasses

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) and Player.TeamColor.Color == "Camo" then
			for ToolObject = 1, #Tools do
				local CloneTool = ToolsParent:FindFirstChild(Tools[ToolObject])
				if CloneTool then
					CloneTool:Clone()
					CloneTool.Parent = Player.Backpack
				end
			end
		end
	end)
end)

I’ve tried replacing the 'Player.TeamColor.Color == “Camo” section with ‘Player.Team.TeamColor.Color,’ 'Player.TeamName == “CITIZEN”. Using the ‘player.teamname’ statement worked, however the player received the tool on every single team.

Use

Player.TeamColor == BrickColor.new("Camo")

Instead of

Player.TeamColor.Color == "Camo"

Teams use BrickColor, and the extra .Color at the end is unnecessary

1 Like

I’ve also tried:

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local MarketService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)

local GamepassID = 68207514
local Tools = {“M40A5”}
local ToolsParent = ReplicatedStorage.ACS_Engine.ToolStorage.Gamepasses

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) and Player:FindFirstChild(“Team”) then
if Player.Team == “CITIZEN” then
for ToolObject = 1, #Tools do
local CloneTool = ToolsParent:FindFirstChild(Tools[ToolObject])
if CloneTool then
CloneTool:Clone()
CloneTool.Parent = Player.Backpack
end
end
end
end
end)
end)

And:

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local MarketService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)

local GamepassID = 68207514
local Tools = {“M40A5”}
local ToolsParent = ReplicatedStorage.ACS_Engine.ToolStorage.Gamepasses

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) and Player:FindFirstChild(“Team”) then
if Player.Team.Name == “CITIZEN” then
for ToolObject = 1, #Tools do
local CloneTool = ToolsParent:FindFirstChild(Tools[ToolObject])
if CloneTool then
CloneTool:Clone()
CloneTool.Parent = Player.Backpack
end
end
end
end
end)
end)

And:

local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local MarketService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)

local GamepassID = 68207514
local Tools = {“M40A5”}
local ToolsParent = ReplicatedStorage.ACS_Engine.ToolStorage.Gamepasses

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) and Player:FindFirstChild(“Team”) then
if Player.Team.TeamColor.Color == “Camo” then
for ToolObject = 1, #Tools do
local CloneTool = ToolsParent:FindFirstChild(Tools[ToolObject])
if CloneTool then
CloneTool:Clone()
CloneTool.Parent = Player.Backpack
end
end
end
end
end)
end)

All of these have failed. Any help would be appreciated, thank you.

There are two ways you can do this, the first one is to check if the player has the gamepass, and then check if the player is in the “CITIZEN” team.
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local MarketService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)

local GamepassID = 68207514
local Tools = {“M40A5”}
local ToolsParent = ReplicatedStorage.ACS_Engine.ToolStorage.Gamepasses

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) then
if Player.Team.Name == “CITIZEN” then
for ToolObject = 1, #Tools do
local CloneTool = ToolsParent:FindFirstChild(Tools[ToolObject])
if CloneTool then
CloneTool:Clone()
CloneTool.Parent = Player.Backpack
end
end
end
end
end)
end)

The second way is to check if the player is in the “CITIZEN” team, and then check if the player has the gamepass.
local

1 Like

The script works fine for the gamepass, but it does not work for the team.
I’m not sure if this is the correct statement for the team color, but as I said before, I’ve tried scripting it on my own, and it didn’t work.
I’m not sure if there is a statement that allows the player to receive tools only for the team that they are in. If there is, I’d appreciate if someone could show me the correct script or correct statement for the team color.
Thanks for reading!

if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) and Player.TeamColor.Color == “Camo” then

This line will only work if they are in the citizen team, as it is looking for their team color.
It should be:
if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) and Player.Team.Name == “CITIZEN” then

Sorry for my late reply, it was 11pm
I’ve just tried this however the script doesn’t work at all anymore - you don’t receive the tool on any team, regardless of if you reset yourself, etc…

1 Like