Buying gamepasses in game does not work

Hey devs,

I have some game passes in my game that give the player gear or whatever the game pass does.

If the player buys it outside of the game, then loads in, then they will get whatever the gamepass gives them. However, if they buy the pass while in game, then they do not receive the item.

I have only tested this in studio with the local server test, but I am assuming its the same either way?

If anyone can give me some guidance on this issue and get me moving in the right direction, please do.

I can provide screenshots, code, whatever you may need if it helps you help me :slight_smile:

1 Like

Make a GUI when buying it saying rejoin to use. idk lol.

1 Like

Do you own that gamepass in your inventory?

2 Likes

I will do this as a last resort lol

1 Like

It would be greatly appreciated if (and you SHOULD be) providing your code for us to look into.

Anyways, gamepasses aren’t self-working. You have to implement a live-gamepass script which will give the player their items when the purchase is finished. Additionally, you could also just tell your player to rejoin the game for their benefits to take place

2 Likes

PowerHouse does it give you it if you reset?

2 Likes

Yes I created all of the gamepasses, so yes since they are naturally added to the creators accounts.

1 Like

No I tried this already; I am assuming it either needs the player to leave or there is an issue in the code

1 Like

Well the problem is, when you buy a gamepass you have to rejoin the game. Only developer products can work live when player buys them.

2 Likes

hm send the game link and make the gampass 1 robux so i can try to help :slight_smile:

2 Likes

Also does it show you any errors? also can you send us the code.

2 Likes

Well I just gotta warn you before hand; this code is extremely messy as I implemented it into my game roughly four years ago haha. That said, making this post is a part of cleaning it up, so thats what I have been working through.

I have 2 scripts:

1 handles Gamepasses; here it is:

Summary
local MartketPlaceService = game:GetService("MarketplaceService")

local players = game:GetService("Players")

pcall(function()
	game.Players.PlayerAdded:connect(function(player)
		if MartketPlaceService:UserOwnsGamePassAsync(player.UserId,1597840) then

			local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
			cashmoney.Value = cashmoney.Value + 10000
			local msg = Instance.new("Hint",workspace)
			player.CharacterAdded:connect(function(char)
				game.Lighting.LaserCannon:Clone().Parent=player.StarterGear
				if char:WaitForChild("Humanoid") then
					char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 30
					char.Humanoid.Health = char.Humanoid.Health + 30
					char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed + 10
					game.Lighting.LaserCannon:Clone().Parent=player.Backpack
				end
			end)
			msg.Text = player.Name.." joined the game as an Executive!"
			wait(2)
			msg:Destroy()
		elseif MartketPlaceService:UserOwnsGamePassAsync(player.UserId,1597332) then

			local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
			cashmoney.Value = cashmoney.Value + 5000
			player.CharacterAdded:connect(function(char)
				if char:WaitForChild("Humanoid") then
					char.Humanoid.MaxHealth = char.Humanoid.MaxHealth + 25
					char.Humanoid.Health = char.Humanoid.Health + 25
					char.Humanoid.WalkSpeed = char.Humanoid.WalkSpeed + 5
					game.Lighting.LaserCannon:Clone().Parent=player.Backpack
				end
			end)
			local msg = Instance.new("Hint",workspace)
			msg.Text = player.Name.." joined the game with Super VIP!"
			wait(2)
			msg:Destroy()

		elseif MartketPlaceService:UserOwnsGamePassAsync(player.UserId,1598126) then

			local cashmoney = game.ServerStorage.MoneyStorage:WaitForChild(player.Name)
			cashmoney.Value = cashmoney.Value + 500
			local msg = Instance.new("Hint",workspace)
			msg.Text = player.Name.." joined the game as a VIP!"
			wait(2)
			msg:Destroy()
			
		end
		
		if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, 14390869) then
			print("player owns music pass")
			local gui = player.PlayerGui
			gui.Radio.Main.CustomFrame.GamepassNeeded.Visible = false
		end

		print("GEAR GAME PASS GEAR GAME PASS GEAR GAME PASS")

		gpid = 1616511 --Game Pass ID
		tools = {"JetPack"} --Put VIP tools in Lighting, then put their exact names here.


		if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, gpid) then
			print("Has One")
			for i = 1,#tools do
				game.Lighting:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
			end
		else
			print("No One")
		end


		two = 1616412 --Game Pass ID
		twotools = {"GrappleHook"} --Put VIP tools in Lighting, then put their exact names here.


		------ DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING


		if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, two) then
			print("Has two")
			for i = 1,#twotools do
				game.Lighting:FindFirstChild(twotools[i]):Clone().Parent = player.Backpack
			end
		else
			print("No two")
		end


		three = 1616331 --Game Pass ID
		threetools = {"BlackHoleBomb"} --Put VIP tools in Lighting, then put their exact names here.


		------ DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING


		if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, three) then
			print("Has three")
			for i = 1,#threetools do
				game.Lighting:FindFirstChild(threetools[i]):Clone().Parent = player.Backpack
			end
		else
			print("No three")
		end


		four = 1616008 --Game Pass ID
		fourtools = {"SubspaceTripmine"} --Put VIP tools in Lighting, then put their exact names here.


		------ DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING


		if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, four) then
			print("Has four")
			for i = 1,#fourtools do
				game.Lighting:FindFirstChild(fourtools[i]):Clone().Parent = player.Backpack
			end
		else
			print("No four")
		end



		five = 1616462 --Game Pass ID
		fivetools = {"ExponentialRocketLauncher"} --Put VIP tools in Lighting, then put their exact names here.


		------ DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING

		if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, five) then
			print("Has five")
			for i = 1,#fivetools do
				game.Lighting:FindFirstChild(fivetools[i]):Clone().Parent = player.Backpack
			end
		else
			print("No five")
		end


		
		
		-- Handles gear on respawn
		
		print("GEAR GAME PASS GEAR GAME PASS GEAR GAME PASS")

		gpid = 1616511 --Game Pass ID
		tools = {"JetPack"} --Put VIP tools in Lighting, then put their exact names here.

		function respawned(char)
			player = game.Players:GetPlayerFromCharacter(char)
			print("Respawned")
			if char:FindFirstChild("Head") ~= nil then
				print("It's a Player!")
				if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, gpid) then
					print("Has One")
					for i = 1,#tools do
						game.Lighting:FindFirstChild(tools[i]):Clone().Parent = player.Backpack
					end
				else
					print("No One")
				end
			end
		end
		player.CharacterAdded:Connect(respawned)


		two = 1616412 --Game Pass ID
		twotools = {"GrappleHook"} --Put VIP tools in Lighting, then put their exact names here.


		------ DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING

		function respawned(char)
			player = game.Players:GetPlayerFromCharacter(char)
			print("Respawned")
			if char:FindFirstChild("Head") ~= nil then
				print("It's a Player!")
				if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, two) then
					print("Has two")
					for i = 1,#twotools do
						game.Lighting:FindFirstChild(twotools[i]):Clone().Parent = player.Backpack
					end
				else
					print("No two")
				end
			end
		end
		player.CharacterAdded:Connect(respawned)


		three = 1616331 --Game Pass ID
		threetools = {"BlackHoleBomb"} --Put VIP tools in Lighting, then put their exact names here.


		------ DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING

		function respawned(char)
			player = game.Players:GetPlayerFromCharacter(char)
			print("Respawned")
			if char:FindFirstChild("Head") ~= nil then
				print("It's a Player!")
				if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, three) then
					print("Has three")
					for i = 1,#threetools do
						game.Lighting:FindFirstChild(threetools[i]):Clone().Parent = player.Backpack
					end
				else
					print("No three")
				end
			end
		end
		player.CharacterAdded:Connect(respawned)


		four = 1616008 --Game Pass ID
		fourtools = {"SubspaceTripmine"} --Put VIP tools in Lighting, then put their exact names here.


		------ DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING

		function respawned(char)
			player = game.Players:GetPlayerFromCharacter(char)
			print("Respawned")
			if char:FindFirstChild("Head") ~= nil then
				print("It's a Player!")
				if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, four) then
					print("Has four")
					for i = 1,#fourtools do
						game.Lighting:FindFirstChild(fourtools[i]):Clone().Parent = player.Backpack
					end
				else
					print("No four")
				end
			end
		end
		player.CharacterAdded:Connect(respawned)


		five = 1616462 --Game Pass ID
		fivetools = {"ExponentialRocketLauncher"} --Put VIP tools in Lighting, then put their exact names here.


		------ DON'T EDIT BELOW UNLESS YOU KNOW WHAT YOU'RE DOING

		function respawned(char)
			player = game.Players:GetPlayerFromCharacter(char)
			print("Respawned")
			if char:FindFirstChild("Head") ~= nil then
				print("It's a Player!")
				if MartketPlaceService:UserOwnsGamePassAsync(player.UserId, five) then
					print("Has five")
					for i = 1,#fivetools do
						game.Lighting:FindFirstChild(fivetools[i]):Clone().Parent = player.Backpack
					end
				else
					print("No five")
				end
			end
		end
		player.CharacterAdded:Connect(respawned)
		
	end)
end)

2 handles Dev Products; here it is

Summary
local MarketplaceService = game:GetService("MarketplaceService")

local function processReceipt(receiptInfo)
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	
		if not player then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	
	print(player.Name.."just purchased".. receiptInfo.ProductId)
	
	if receiptInfo.ProductId == 42820232 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 5000
		end
	end
	
	if receiptInfo.ProductId == 42820276 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 10000
		end
	end	
	
	if receiptInfo.ProductId == 42820303 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 25000
		end
	end	
	
	if receiptInfo.ProductId == 42820329 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 100000
		end
	end	
	
	if receiptInfo.ProductId == 42820348 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 500000
		end
	end	
	
	if receiptInfo.ProductId == 1145512229 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 1000000
		end
	end	
	
	if receiptInfo.ProductId == 42870511 then
		local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
		if cashmoney then
			cashmoney.Value = cashmoney.Value + 999999999
		end
	end	
	
	if receiptInfo.ProductId == 14390869 then
		print("player bought music pass")
		local gui = player.PlayerGui
		gui.Radio.Main.CustomFrame.GamepassNeeded.Visible = false
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt

I am not sure if the codes are flawed to begin with since it is split in two scripts? As I said this was implemented 4 years ago and I am trying to clean it up, so please let me know what needs changed.

I just sent the code in a previous reply (sorry for the messy mess haha)

But I remember back when I started to develop that I thought players had to rejoin for gamepasses to work, but I wasn’t sure if that was still the case.

But no, I don’t get any errors with this code; surprisingly.

Not necessarily the case, you can use PromptGamePassPurchaseFinished

@PowerHouse2424

3 Likes

I would I want to include this in the local script that prompts the purchase?

Which would be this script that is within the GUI button:

script.Parent.MouseButton1Click:Connect(function()
	MPS:PromptProductPurchase(player, dp)
end)

Or would I put it in one of the server scripts?

just do when the player buys it.

boughtFunction(player)
local tool = game.ServerStorage.tool:Clone()
tool.Parent = player.Backpack
local spawnTool = game.ServerStorage.tool:Clone()
spawnTool.Parent = game.StarterPack
end

1 Like

Are you prompting a dev product or a gamepass?

1 Like

When you first buy a gampass for some reason it doesnt work. When you rejoin it is just fine.

Dont over think it its a roblox thing nothings wrong with the code.

1 Like

Gamepass. I already have dev products working.

I used MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player,asset,bool)

and this seems to have the trick as you. The player only has to reset and they get their gear.