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

How to form game currency?

Asked by 9 years ago

I've been trying endlessly to process a script to formulate game currency, nothing has worked out well. Many games nowadays have an in-game currency that players can use to purchase game items, upgrade items, etc. I'm trying to figure out how this is done. This is obviously a big task and I'm a little in over my head, but it's required for the game I'm developing. My game is a Halloween themed game and the game "Currency" is candy. Is there a way to create this so that players can purchase more candy (through developer products), use it to purchase items through a gui store (items should stay purchased when the player joins the game again), and keep their candy amount when they join the game again?

The script below is a purchase processor but I'm been stuck since making this.

repeat wait() until script.Parent.Name == 'ServerScriptService'
local MarketplaceService = Game:GetService('MarketplaceService')
test = false 

MarketplaceService.ProcessReceipt = function(receiptInfo)

    local playerData = PlayerDataStore:GetSaveDataById(receiptInfo.PlayerId)

    playerData:Update({'Purchases', 'InGameMoney'}, function(oldPurchases, oldMoney)

        if not oldPurchases then oldPurchases = {} end

        if not oldPurchases[receiptInfo.PurchaseId] then

            if receiptInfo.CurrencySpent > 1 and receiptInfo.CurrencyType == Enum.CurrencyType.Tix and not test then
            amount = receiptInfo.CurrencySpent / 1/2 
            oldMoney = oldMoney + amount
            elseif receiptInfo.CurrencySpent > 1 and receiptInfo.CurrencyType == Enum.CurrencyType.Robux and not test then
            amount = receiptInfo.CurrencySpent / receiptInfo.CurrencySpent 
            oldMoney = oldMoney + amount
        end
        return oldPurchases, oldMoney
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted
end)
end

Answer this question