Gamepass script not giving me the gear despite that i owned the gamepass?

Hi!

So I was given a working script to help me with adding gears into a game when they owned a gamepass, simple right?

Oddly, even after adding the id of the gamepass and the name of the gear (and add it in the storage server as required), it doesn’t load in at all.

here is the script:

local Id = 15048165
local ToolName = {“RainbowMagicCarpet”}

for _, Player in pairs(game.Players:GetChildren()) do
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId, Id) then 
        Player.CharacterAdded:Connect(function(character)
			for Num, Tool in pairs(ToolName) do
				if game:GetService("ServerStorage"):FindFirstChild(Tool) then
					if Player.Backpack:FindFirstChild(Tool) then
					else
						game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
					end
				end
			end
		end)
		
		for Num, Tool in pairs(ToolName) do
			if Player.Backpack:FindFirstChild(Tool) == nil then
				if game:GetService("ServerStorage"):FindFirstChild(Tool) then
					if Player.Backpack:FindFirstChild(Tool) then
					else
						game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
					end
				end
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(Player)
if game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(Player.UserId, Id) then
Player.CharacterAdded:Connect(function(character)
for Num, Tool in pairs(ToolName) do
if game:GetService(“ServerStorage”):FindFirstChild(Tool) then
if Player.Backpack:FindFirstChild(Tool) then
else
game:GetService(“ServerStorage”)[Tool]:Clone().Parent = Player.Backpack
end
end
end
end)

		for Num, Tool in pairs(ToolName) do
			if Player.Backpack:FindFirstChild(Tool) == nil then
				if game:GetService("ServerStorage"):FindFirstChild(Tool) then
					if Player.Backpack:FindFirstChild(Tool) then
					else
						game:GetService("ServerStorage")[Tool]:Clone().Parent = Player.Backpack
					end
				end
			end
		end
	end

end)

Am I missing something in this script in order to work?

I checked everywhere and they always say to add the id of the gamepass and name of the gear (I was hoping for adding the id of the gear, but oh well.)

Has your game printed any errors in the F9 console?

Hello! Seeing this script it makes me feel It’s overcomplicating for the solution.

I see you want to make it so if the player has the gamepass it gives the tool. This can be done by simply inserting the tools in ServerStorage and with a PlayerAdded connection check if the tool is in ServerStorage and clone it to the player’s backpack and startergear.

local MarketService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local Id = 15048165
local ToolNames = {"Tool1", "Tool2"}

Players.PlayerAdded:Connect(function(player)
	if MarketService:UserOwnsGamePassAsync(player.UserId , Id) then
		for i,Name in pairs (ToolNames) do
			local Tool = game.ServerStorage[Name]
			if Tool then
				Tool:Clone().Parent = player.Backpack
				Tool:Clone().Parent = player.StarterGear
			end
		end
	end
end)

This checks for every name in ToolNames to see if they exist in ServerStorage, if so then it’ll clone to the player’s Backpack and StarterGear

2 Likes

I checked with the /console, no errors at all.

so can I just put RainbowMagicCarpet inside the tool1 name and it’ll give them the gear if they owned the gamepass?

Yep, that’s how it works. You can put how many tool names you want and if the user has that gamepass it’ll give each one of them.

Odd, it didn’t gave me the gear (I’m just doing one gear per gamepasses), any ideas why?

Im using the same script you gave me with the right id in game and even spell the gear name correctly.

Make sure your gear is in ServerStorage, you can put a WaitForChild() in local Tool if you want.

However this script works completly fine for me, it gives me both tools when I enter the game and when I die.

Of course it won’t work if you buy the gamepass while in-game, since It’s connected to PlayerAdded, to fix that you can make this script a function:

function GiveTool(player)
	if MarketService:UserOwnsGamePassAsync(player.UserId , Id) then
		for i,Name in pairs (ToolNames) do
			local Tool = game.ServerStorage[Name]
			if Tool then
				Tool:Clone().Parent = player.Backpack
				Tool:Clone().Parent = player.StarterGear
			end
		end
	end
end

And use it in the PlayerAdded Connection and through PromptGamePassPurchaseFinished

It’s already in the storageserver, plus it’s in the gamepass page since I’m not too worried about having to buy in game atm.

Make sure the script is inside ServerScriptService.

nope, it didn’t work anyway. I’m very annoyed, this is an easy script and yet it doesn’t want to work.

Use prints between lines to see where it fails.

Hey you can use my script which I use its simple and easy to use:

local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassID = 5059047 -- Put the gamepads id here
local tool = game.ServerStorage.[Insert Tool] --Put tool name here

game.Players.PlayerAdded:Connect(function(player)

	if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassID) then --if player has gamepass then

tool:Clone().Parent = player:WaitForChild("Backpack")
tool:Clone().Parent = player:WaitForChild("StarterGear")
		--Moves tool into players Backpack
	end
end)