Game pass script doesn't always give the player gear

I am trying to make two game passes give you two separate gears. The script works sometimes but oftentimes only gives me the “Speed” gear.

local GamePass = game:GetService("MarketplaceService")
game:GetService("Players").PlayerAdded:Connect(function(plr)
    if GamePass:UserOwnsGamePassAsync(plr.UserId,9146292) then
        local tool = game:GetService("ServerStorage"):FindFirstChild("Gravity"):Clone()
        tool.Parent = plr:WaitForChild("Backpack")
    end
    if GamePass:UserOwnsGamePassAsync(plr.UserId,9146295) then
        local tool = game:GetService("ServerStorage"):FindFirstChild("Speed"):Clone()
        tool.Parent = plr:WaitForChild("Backpack")
    end
end)

I wrote this script with the help of the Roblox Wiki, but in the example they gave it was only using one game pass. (The Script is in ServerScriptService)

This is the game-pass gear scrip I use. It should work, never had an issue with it.

--------------------
--| WaitForChild |--
--------------------

-- Waits for parent.child to exist, then returns it
local function WaitForChild(parent, childName)
	assert(parent, "ERROR: WaitForChild: parent is nil")
	while not parent:FindFirstChild(childName) do parent.ChildAdded:wait() end
	return parent[childName]
end

-----------------
--| Variables |--
-----------------

local GamePassService = Game:GetService('GamePassService')
local PlayersService = Game:GetService('Players')
local InsertService = Game:GetService('InsertService')
local LightingService = Game:GetService('Lighting') --TODO: Use new data store service once that exists

local GamePassIdObject = WaitForChild(script, 'GamePassId')
local ToolAssetsToLoad = WaitForChild(script, 'ToolAssetsToLoad')

local AdminTools = LightingService:FindFirstChild('AdminTools')

-----------------
--| Functions |--
-----------------

-- Makes copies of all the admin tools and puts them in target
local function CloneAdminTools(target)
	for _, tool in pairs(AdminTools:GetChildren()) do
		local toolClone = tool:Clone()
		toolClone.Parent = target
	end
end

-- When a player with the game pass joins, give them the admin tools
local function OnPlayerAdded(player)
	if GamePassService:PlayerHasPass(player, GamePassIdObject.Value) then
		local starterGear = WaitForChild(player, 'StarterGear')
		CloneAdminTools(starterGear)
		if player.Character then -- They've already loaded and won't get their StarterGear until next spawn
			local backpack = WaitForChild(player, 'Backpack')
			CloneAdminTools(backpack)
		end
	end
end

--------------------
--| Script Logic |--
--------------------

-- Create AdminTools if it doesn't exist
if not AdminTools then
	AdminTools = Instance.new('Model')
	AdminTools.Name = 'AdminTools'

	-- Load all of the assets in ToolAssetsToLoad and put them in AdminTools
	for _, intObject in pairs(ToolAssetsToLoad:GetChildren()) do
		if intObject and intObject:IsA('IntValue') and intObject.Value then
			local assetModel = InsertService:LoadAsset(intObject.Value)
			if assetModel then
				local asset = assetModel:GetChildren()[1]
				if asset then
					asset.Parent = AdminTools
				end
			end
		end
	end

	AdminTools.Parent = LightingService
end

PlayersService.PlayerAdded:connect(OnPlayerAdded)

It’s a normal script and put an IntValue with the gamepass ID in it. Then a group called “ToolAssetsToLoad” and another int value with the tool ID.

Here is a FM I just made this should work:

https://www.roblox.com/library/4951669114/Game-pass-Gear-Loader

1 Like

They are definitely game pass IDs

1 Like

Your just adding it to the backpack, you would need to add it to the StarterGear as well

No adding to the backpack is enough. StarterGear will clone the tool to every player’s backpack.

local GamePass = game:GetService("MarketplaceService")
game:GetService("Players").PlayerAdded:Connect(function(plr)
    if GamePass:UserOwnsGamePassAsync(plr.UserId,9146292) then
        local tool = game:GetService("ServerStorage"):FindFirstChild("Gravity"):Clone()
        tool.Parent = plr:WaitForChild("Backpack") .. ("StarterGear")
    end
    if GamePass:UserOwnsGamePassAsync(plr.UserId,9146295) then
        local tool = game:GetService("ServerStorage"):FindFirstChild("Speed"):Clone()
        tool.Parent = plr:WaitForChild("Backpack") .. ("StarterGear")
    end
end)

Yikes That totaly broke it.


I will test that as well

1 Like

I need to have two game passes and the gear is a modified version of what is on the catalog so I am not sure if this one would work.

You can duplicate this by doing command d and fill the info out again at least that’s what I did. Plus it’d be easier to remove any game-passes in the future instead of having to select lines of code to delete and rewriting it for a new amount.

2 Likes

It will not. You’re thinking of StarterPack.

StarterGear is underneath every player, and will give it to that one player every spawn.

I see three potential issues here:

  • If the PlayerAdded event is connected after the player joins, it won’t run that code;
  • If the Player’s character hasn’t loaded when you add the gamepass to their backpack it won’t be added; and
  • If the player dies, the gamepass will leave their inventory.

The solution is to clone it into both StarterPack and StarterGear.

local GamePass = game:GetService("MarketplaceService")
game:GetService("Players").PlayerAdded:Connect(function(plr)
    if GamePass:UserOwnsGamePassAsync(plr.UserId,9146292) then
        game:GetService("ServerStorage"):FindFirstChild("Gravity"):Clone().Parent = plr:WaitForChild("Backpack")
        game:GetService("ServerStorage"):FindFirstChild("Gravity"):Clone().Parent = plr:WaitForChild("StarterGear")
    end
    if GamePass:UserOwnsGamePassAsync(plr.UserId,9146295) then
        game:GetService("ServerStorage"):FindFirstChild("Speed"):Clone().Parent = plr:WaitForChild("Backpack")
        game:GetService("ServerStorage"):FindFirstChild("Speed"):Clone().Parent = plr:WaitForChild("StarterGear")
    end
end)```
3 Likes