I am trying to edit this script so when the developer product is bought the “Wins” leaderstat will be given to the player.
script:
local MarketplaceService = game:GetService("MarketplaceService")
local SoundService = game:GetService("SoundService")
-- Developer Product IDs
local productIds = {
WB10 = 1891245344, -- Replace with actual Developer Product ID
WB25 = 1891245456, -- Replace with actual Developer Product ID
WB50 = 1891245696, -- Replace with actual Developer Product ID
WB75 = 1891245817, -- Replace with actual Developer Product ID
WB100 = 1891245994, -- Replace with actual Developer Product ID
WB200 = 1891246124, -- Replace with actual Developer Product ID
}
-- Sound to play on button click
local clickSound = Instance.new("Sound")
clickSound.SoundId = "rbxassetid://876939830" -- Replace with actual sound asset ID
clickSound.Parent = SoundService
-- Function to handle button click
local function onButtonClick(button)
local productId = productIds[button.Name]
if productId then
clickSound:Play()
local player = game.Players.LocalPlayer
MarketplaceService:PromptProductPurchase(player, productId)
else
warn("No product ID found for button: " .. button.Name)
end
end
-- Attach click event to all buttons
local donateButtonsFolder = script.Parent
for i, button in donateButtonsFolder:GetChildren() do
if button:IsA("TextButton") then
button.MouseButton1Click:Connect(function()
onButtonClick(button)
end)
end
end
The number that is next to the “WB” in the product ID table is the amount of wins given when buying the developer product. Like the first one is “WB10” so 10 wins will be given
You’d need to use the MarketplaceService.ProcessReceipt callback on the server to do this.
local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local productFunctions = {}
--make a structure like this for each of your developer products
--you may want to use a module and require it
productFunctions[YourProductIdHere] = function(player: Player)
--give the benefits here
end
--this is the main callback
local function processReceipt(receipt: {[string]: any}): Enum.ProductPurchaseDecision
local userId: number = receipt.PlayerId --the UserId of the player that bought a product
local productId: number = receipt.ProductId --the asset ID of the developer product purchased
--get the player and the callback
local player: Player = players:GetPlayerByUserId(userId)
local handler: (Player) -> (nil) = productFunctions[productId]
--run the callback in protected mode
local success: boolean, result: string? = pcall(handler, player)
if success then --benefits awarded, let Roblox know
return Enum.ProductPurchaseDecision.PurchaseGranted
else --failed to process, let Roblox know so this will be run again when the player next joins
return Enum.ProductPurchaseDecision.NotProcessedYet
end
end
--set the callback (this can only be done once by a server script)
mps.ProcessReceipt = processReceipt