Gamepasses Don't Give Tools

Hi all, I tried to make a gamepass GUI for two classic tools - Speed Coil and Jump Coil. For some reason though when I purchase the gamepass it doesn’t give me the tools. Here are my scripts:

Script in ServerScriptService

local mps = game:GetService("MarketplaceService")
local gamepass_id = 17930931 --enter the gamepass asset id here
local plrs = game:GetService("Players")

game.Players.PlayerAdded:Connect(function(player)
	if mps:UserOwnsGamePassAsync(player.UserId , gamepass_id) then
		game.ServerStorage.JumpCoil:Clone().Parent = player.Backpack
		game.ServerStorage.JumpCoil:Clone().Parent = player.StarterGear
	end
end)

Local Script in the Purchase GUI Text Button

local ID = 17930931 -- JumpCoil ID
script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,ID) -- Prompts the purchase
end)

Thanks!

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

Yeah, the player will need to rejoin in order to recieve the tools since the mps:UserOwnsGamePassAsync condition check happens only once. I suggest adding an extra player.CharacterAdded event in which you will place that condition so instead of rejoining the player would need to reset to recieve these tools.

1 Like

Is there any way that I can make it so no resetting/rejoining needs to happen for the player to get the item?

make a PromptGamepassPurchaseFinished function to make the player to get it once they bought without rejoining

1 Like
local MarketplaceService = game:GetService("MarketplaceService")
 
local gamePassID = {gamepass id}

-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
	if purchaseSuccess == true and purchasedPassID == gamePassID then
		--give the tools
	end
end

-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
2 Likes

Not sure if I did it right, but unfortunately it doesn’t work yet:

local MarketplaceService = game:GetService("MarketplaceService")

local gamePassID = {17930931}

-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
	if purchaseSuccess == true and purchasedPassID == gamePassID then
		game.ServerStorage.JumpCoil:Clone().Parent = player.Backpack
		game.ServerStorage.JumpCoil:Clone().Parent = player.StarterGear
	end
end

-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)

You should probably remove the brackets {}

If the error persists, please provide a screenshot of the output.

3 Likes

The gamePassID is assuming that the variable is a “table”, or an amount of objects to hold

Example of a table:

{"Yes", 50, true, workspace.Baseplate} --Basically this

Just remove the brackets and you should be fine with referencing it as a singular variable

2 Likes
local MarketplaceService = game:GetService("MarketplaceService")

local gamePassID = (17930916)

-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
	if purchaseSuccess == true and purchasedPassID == gamePassID then
		game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
		game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear
	end
end

-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
local ID = 17930916 -- SpeedCoil ID
script.Parent.MouseButton1Click:Connect(function()
	game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer,ID) -- Prompts the purchase
end)


Are you getting any errors on the Output at all?

1 Like

Nevermind, that part works - it gives the tool now. The only thing is, when I leave and rejoin I no longer have the tools.
How do I make it so I get the tools on rejoin as well?

You could just combine your 2 scripts into 1:

local MarketplaceService = game:GetService("MarketplaceService")
local SpeedCoil = 17930916
local GravityCoil = 17930931 

game.Players.PlayerAdded:Connect(function(player)
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId , GravityCoil) then
		game.ServerStorage.JumpCoil:Clone().Parent = player.Backpack
		game.ServerStorage.JumpCoil:Clone().Parent = player.StarterGear
	end

	if MarketplaceService:UserOwnsGamePassAsync(player.UserId , SpeedCoil) then
		game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
		game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear
	end
end)

-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
	if purchaseSuccess == true then
        if purchasedPassID == SpeedCoil then
		    game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
		    game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear

        elseif purchasedPassID == GravityCoil then
		    game.ServerStorage.GravityCoil:Clone().Parent = player.Backpack
		    game.ServerStorage.GravityCoil:Clone().Parent = player.StarterGear
        end
	end
end

-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
1 Like

And this goes in the serverscript script right?

Correct-a-mundo, do make sure to check your Output for any potential errors I missed

1 Like

Unfortunately doesn’t save and only one the speed coil is given to the player, weird.

1 Like

Maybe try this inside your PlayerAdded event?

game.Players.PlayerAdded:Connect(function(player)
    print("Player added")
	if MarketplaceService:UserOwnsGamePassAsync(player.UserId , GravityCoil) then
        print("Gravity coil given")
		game.ServerStorage.JumpCoil:Clone().Parent = player.Backpack
		game.ServerStorage.JumpCoil:Clone().Parent = player.StarterGear
	end

	if MarketplaceService:UserOwnsGamePassAsync(player.UserId , SpeedCoil) then
        print("Speed coil given")
		game.ServerStorage.SpeedCoil:Clone().Parent = player.Backpack
		game.ServerStorage.SpeedCoil:Clone().Parent = player.StarterGear
	end
end)
2 Likes