How do i fix this gamepass bug?

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local GamepassIds = require(game.ReplicatedStorage.Configuration.Modules.Gamepasses)

local ID = 1382081575

Players.PlayerAdded:Connect(function(player)
	local Configuration = player:WaitForChild("Configuration")

	local SpeedBoost = Configuration:WaitForChild("SpeedBoostGamepass")

	local function CheckGamepass()

		print("check gamepass")
		if MarketplaceService:UserOwnsGamePassAsync(player.UserId, ID) then
			print("Gamepass active!")
			SpeedBoost.Value = true
		end
	end

	CheckGamepass()

	MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(plr, gamePassId, wasPurchased)
		if plr == player and wasPurchased and gamePassId == ID then
			print("PURCHASE")
						
			CheckGamepass()
		end
	end)
end)

Hi,
For some unknown reason, the gamepass isn’t activated when I buy the gamepass, even though the id is the same.

Thanks in advance!

1 Like

MarketplaceService.UserOwnsGamePassAsync caches its results. You’ll need to have the player rejoin.

1 Like

any way to know if the player has bought the gamepass in the same session?

Not unless you use the purchased Boolean parameter provided by MarketplaceService.ProkptGamePassPurchaseFinished, but iirc exploiters can spoof that with incorrect parameters even for gamepasses they do not own, tricking your code into thinking they bought it when they didnt.

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