Team Gamepass Item

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)

end

Players.PlayerAdded:Connect(onPlayerAdded)

Sorry if its a bit confuse, im new to scripting.

Oh no the code it’s all formatted wrong

Ok here’s what I’d suggest:

  • 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)
1 Like

Thanks man, that really helped, imma keep this if some new dev like me want to know.

Well i think not, i tested it, nothing happened.

maybe the team instance is wrong

imma try teamcolor instance, maybe it works

also no, im not that good at scripting, maybe its something simple and i dont know.

Calm down geez

Are you getting anything from your output at all? Or no?

Maybe try this?

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)
2 Likes

NOW it worked, maybe because it missed to get the service. Imma keep the thread.