Teleport to the end GUI developer product

Hello everyone,

I’m currently developing a guessing game and I’ve been working on incorporating a UI/GUI. I’m aiming to create a button that, when clicked, will prompt players to purchase a developer product. Upon successful purchase, the player will be teleported to the game’s end.

I’d like to ensure that the button functions as intended, teleporting a player only once per purchase. To teleport again, you would require another product purchase.

I’m eager to hear any suggestions or advice you might have on implementing this feature effectively. Thank you for your time and consideration.

2 Likes

Use the .MouseButton1Click event to listen for the player’s click on a GuiButton object like a TextButton or an ImageButton, and inside that event you would prompt the player with a developer product purchase through the :PromptProductPurchase method all inside a local script.

On the server, you would use the ProcessReceipt callback to handle the purchase and have a table of functions with a index the same as the developer product Id. You would wrap this function around a pcall and if it goes well, return Enum.ProductPurchaseDecision.PurchaseGranted to tell ROBLOX that the purchase was successful and if not, return Enum.ProductPurchaseDecision.NotProcessedYet

3 Likes

I kind of understood what you were saying but i am not a scripter so i barely understood everything, if possible could you provide me a script.

1 Like

I mean… sure.

Inside a TextButton or an ImageButton depending on which one you are choosing, you would have a LocalScript as a child and inside that LocalScript you would have the following code:

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

local Button = script.Parent
local localPlayer = Players.LocalPlayer
local productID = 00000000000 -- Replace this with the Id you want to prompt

Button.MouseButton1Click:Connect(function()
    MarketplaceService:PromptProductPurchase(localPlayer, productId)
end)

And on the server, you would have a Script in ServerScriptSerivce that would go like this:

--!strict

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

type ReceiptType = {
	PurchaseId: string,
	PlayerId: number,
	ProductId: number,
	PlaceIdWherePurchased: number,
	CurrencySpent: number,
	CurrencyType: Enum.CurrencyType
}

local productIds = {
	[00000000] = function(player: Player): (boolean) -- Change the id to the id you desire
		-- Here you would have the desired effect of your developer product
		-- Just make sure to return true as it is required. I've already done that for you
		
		return true
	end,
}

local function onProcessReceipt(receiptInfo: ReceiptType)
	local playerId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId
	
	local player = Players:GetPlayerByUserId(playerId)
	if player then -- We make sure if the player is currently inside the server
		local func = productIds[productId]
		if not func then return end
		
		local success, result = pcall(func, player)
		
		if success then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Error processing receipt: " .. tostring(result))
		end
	end
	
	-- If all previous 'if statements' weren't met then
    -- we will tell ROBLOX that the purchase has gone
    -- unsuccessful
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

MarketplaceService.ProcessReceipt = onProcessReceipt
1 Like

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