Gamepasses won't give tools to players after purchase

I’ve tried scripting so when players purchase the gamepass in-game it should be in their inventory after the purchase, however it hasn’t worked.
I’ve got these 2 scripts, one inside the gui to open the shop and the other inside ServerScriptService

local MarketplaceService = game:GetService("MarketplaceService")

local MainFrame = script.Parent.MainFrame
local gravityGamepass = MainFrame.GravityCoilFrame.GravityGamepass
local OpenShop = MainFrame.Parent.OpenShop

local player = game.Players.LocalPlayer

local gravityGamepassID = 11849329

gravityGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gravityGamepassID)	
	end)

	if hasPass then
		print("player already has the gamepass")
	else
		MarketplaceService:PromptGamePassPurchase(player, gravityGamepassID)
	end	
end)
	
OpenShop.MouseButton1Down:Connect(function()
	MainFrame.Visible = not MainFrame.Visible
	

end)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gravityGamepassID = 11849329


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

	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gravityGamepassID)

	end)
	 
	if hasPass then
		print("player has the gamepass")

		local GravityCoil = game.ReplicatedStorage.GravityCoil:Clone()
		GravityCoil.parent = player.Backpack
	end	
end)

local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)

	if purchaseSuccess == true and purchasedPassID ==  gravityGamepassID then
		print(player.Name . . " purchased the gamepass")

		local GravityCoil = game.ReplicatedStorage.GravityCoil:Clone()
		GravityCoil.parent = player.Backpack
	end
end


MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)
	

1 Like

While I don’t really know what the solution is to the issue, let me just point out something.

Instead of making a global variable like this,

gravityGamepass.MouseButton1Down:Connect(function(plr)
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gravityGamepassID);
    end)
end)

You could just do:

gravityGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
		return MarketplaceService:UserOwnsGamePassAsync(player.UserId, gravityGamepassID);	
	end)
end)

Since after all, you are already setting it to the “message” variable. You are basically returning/sending it to the “message” variable. With that being said, you should also check for success.

gravityGamepass.MouseButton1Down:Connect(function(plr)
    local success, message = pcall(function()
        return MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gravityGamepassID);
    end)

    
    if success then --check if marketplaceservice request was successful
        if message then --check if player has gamepass
            print("Player has gamepass.");
        else
            warn("Player " .. plr.UserId .. " does not have the gamepass.");
        end
    end
end)