Items bought from gamepass in-game only giving items when rejoining the game

Hi guys, I have made rainbow carpet, gravity coil, speed coil, grapple hook and radio. They all work. However the player needs to rejoin the game so that the items can appear in the backpack. How do I make so that when the player buys the gamepasses, it gives them the item immediately?

You can connect a function to MarketplaceService’s PromptGamePassPurchaseFinished event.

1 Like

Could you tell me how the code would be like with the command? Sorry it’s been years since I don’t use rblx studio. Here’s the code by the way, I’ll give you the ServerScriptService one, i think that’s the one that should be needed idk

Code

local gamepassId = 800050561
local mps = game:GetService(“MarketplaceService”)

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
if mps:UserOwnsGamePassAsync(player.UserId,gamepassId) then
game:GetService(“ServerStorage”).RainbowMagicCarpet:Clone().Parent = player.Backpack
print(player.Name…" owns the flying carpet gamepass")
end
end)
end)

When the gamepass is successfully purchased, the player will receive the tool or item.

-- Server Code
local function check(player, gamePassId, wasPurchased)
	if gamePassId == 1 and wasPurchased then
		-- Clone the item to the Backpack.
		print("Item 1 was purchased.")
	elseif gamePassId == 2 and wasPurchased then
		-- Clone the item to the Backpack.
		print("Item 2 was purchased.")
	end
end
game:GetService("MarketplaceService").PromptGamePassPurchaseFinished:Connect(check)

-- Client Code
game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamepassId)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.