Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How am I able to make a gamepass give in-game cash?

Asked by 7 years ago

Iv'e been looking at a few scripts and each one I try says GamePassService and I have heard that it GamePassService does not work anymore so what I am I able to do?

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

*Script Location: ServerScriptService

Script Information: This handles purchases **(note, you can only have one script handling purchases per game)***

local MarketplaceService = game:GetService("MarketplaceService")
local gamepassid = 0

function getPlayerFromId(id)
    for i,v in pairs(game.Players:GetChildren()) do
        if v.userId == id then
            return v
        end
    end
    return nil
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
    local productId = receiptInfo.ProductId
    local playerId = receiptInfo.PlayerId
    local player = getPlayerFromId(playerId)
    if productId == gamepassid then
        player.leaderstats.cash.Value = player.leaderstats.cash.Value + 300
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

*Script Location: StarterGui

Script Information: This handles the purchasing when you click a button*

local plr = game.Players.LocalPlayer
local button = script.Parent
local gamepassid = 0

button.MouseButton1Down:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(plr, gamepassid)
end)

Hope that helped :)

Ad

Answer this question