My script is not working!

Hello guys, So i made a gamepass script in the serverscriptservice and decided not to do in starterscript(Because i already made the rest of the dev products in that script) so i tried to do it and this thing is not working!

local function promptpurchase(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId
	local haspurch = false

	local player = Players:GetPlayerByUserId(userId)
	if player then
		-- Get the handler function associated with the developer product ID and attempt to run it
		local handler = productFunctionsgamepass[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			-- The user has received their benefits!
			-- return PurchaseGranted to confirm the transaction.
			haspurch = Marketplaceservice:UserOwnsGamePassAsync(player.UserId, handler)
			player.PlayerGui.ScreenGui.Purchasesucessfull.Visible = true
			return Enum.ProductPurchaseDecision.PurchaseGranted

		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end
end

Marketplaceservice.PromptGamePassPurchaseFinished:Connect(promptpurchase)

this is the product function

productFunctionsgamepass[259204857] = function(receipt, player)
	local vip = player:WaitForChild("VIP")
	local gamepassvip = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId , VIP)
	if gamepassvip then
		if vip then
			player.VIP.Value = true
			player.PlayerGui.ScreenGui.Purchasesucessfull.Visible = true
		end
	end
		
end

Why are you doing a combination of gamepass and devproduct handling in the one series of code?

Is the purchase a gamepass or a devproduct?

1 Like

I combined both of them in one script because i thought gamepasses would also work with dev products :sweat_smile:

Keep them seperate. Dev products require specific handling, while gamepasses do not. Combining them will likely just cause errors.

should i make it in local script or in server only?

server sided. 99% of things will find server sided more useful

Yeah but the problem is that it says that it needs playerId which is the
“userid = receiptinfo.playerid”?

For devproduct, yes.

For gamepass, you just go game.Players:FindFirstChild(PlayerName) (or just Player, from PlayerAdded) then get the ID by doing Player.UserId