I would like to try to make a gamepass that gives a gamepass only for a team , example:
The prisoner team player would receive a weapon if he had the gamepass, on other teams no.
The code im using as base:
local Lighting = game:GetService(“Lighting”)
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local gamepassId = 0
local toolNames = {“Five SeveN”}
local toolsParent = Lighting
local function onPlayerAdded(player)
local function onCharacterAdded(character)
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId) then
for i = 1, #toolNames do
local tool = toolsParent:FindFirstChild(toolNames[i])
if tool then
local clone = tool:Clone()
clone.Parent = player.Backpack
end
end
end
end
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)
Your variables are fine, but the darn code format with the quotes make it difficult to copy/paste
You can get the Player’s Team by checking their TeamColor or TeamName properties I believe (I’m not sure if you can check for the actual Team Instance?)
Try to avoid putting the tools inside the Lighting service, ServerStorage would be better instead
local ServerStorage = game:GetService("ServerStorage")
local MarketService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local GamepassID = 0
local Tools = {"Five SeveN"}
local ToolsParent = ServerStorage
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) and Player.TeamName == "Prisoner" 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)
local ServerStorage = game:GetService("ServerStorage")
local MarketService = game:GetService("MarketplaceService")
local Teams = game:GetService("Teams")
local Players = game:GetService("Players")
local GamepassID = 0 -- replace 0 with gamepass id
local Tools = {"Five SeveN"}
local ToolsParent = ServerStorage
local Team = Teams.Prisoner
Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
if MarketService:UserOwnsGamePassAsync(Player.UserId, GamepassID) and Player.Team == Team then
for ToolObject = 1, #Tools do
local Tool = ToolsParent:FindFirstChild(Tools[ToolObject])
if Tool then
local CloneTool = Tool:Clone()
CloneTool.Parent = Player.Backpack
end
end
end
end)
end)