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

When buying dev products, it doesn't give cash amount in-game. Help?

Asked by 7 years ago
Edited 7 years ago

The script is perfect but it just doesn't change cash value in-game I honestly don't know what's wrong with it. Cash is stored in Serverstorage called "Moneystorage"

This is the script for the GUI to buy money

Market = game:GetService("MarketplaceService")
Player = game.Players.LocalPlayer
GUI = script.Parent
Buttons = GUI:WaitForChild("Buttons")
DevProds = {
    {"1K",43938448};
    {"2.5K",43938430};
    {"5K",43938361};
    {"10K",43938334};
    {"100K",0};
    {"250K",0};
    {"1M",0};
    {"2M",0};
}
GamePasses = {
    {"Bonus",551506583};
    {"Infinite",551507212};
}

for k,v in pairs(DevProds) do
    local button = Buttons:WaitForChild(v[1])
    button.MouseButton1Click:connect(function()
        Market:PromptProductPurchase(Player,v[2])
    end)
end

for k,v in pairs(GamePasses) do
    local button = Buttons:WaitForChild(v[1])
    button.MouseButton1Click:connect(function()
        Market:PromptPurchase(Player,v[2])
    end)
end

And here is the Event handler

local Market,PurchaseHistory
testing = false
DevProds = {
    {1000,43938448};
    {5000,43938430};
    {10000,43938361};
    {25000,43938334};
}
GamePasses = {
    {14000,551506583};
    {1e7,551507212};
}

function AddMoney(player,amount)
    local cashmoney = game.ServerStorage:WaitForChild("MoneyStorage"):WaitForChild(player.Name)
    cashmoney.Value = cashmoney.Value+amount
end

function updateValues()
    if Market == nil then
        Market = game:GetService("MarketplaceService")
    end
    if PurchaseHistory == nil and testing == false then
        PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
    end
end

game.Players.PlayerAdded:connect(function(player)
    updateValues()
    if player:IsInGroup(2767505) then
        local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(plr.Name)
        if cashmoney then
            cashmoney.Value = cashmoney.Value + 500
        end
    end
    for _,v in pairs(GamePasses) do
        if Market:PlayerOwnsAsset(player,v[2]) or v.userId == 157510912 then
            AddMoney(player,v[1])
        end
    end
end)

function Market.ProcessReceipt(receiptInfo)
    updateValues()
    local playerProductKey = receiptInfo.PlayerId..":"..receiptInfo.PurchaseId
    if testing == false and PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
    if player == nil then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end
    for _,v in pairs(DevProds) do
        if v[2] == receiptInfo.ProductId then
            AddMoney(player,v[1])
        end
    end
    if testing == false then
        PurchaseHistory:SetAsync(playerProductKey,true)
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted 
end

Market.PromptPurchaseFinished:connect(function(player,assetId,purchased)
    if not purchased then
        return
    end
    for _,v in pairs(GamePasses) do
        if v[2] == assetId then
            AddMoney(player,v[1])
        end
    end
end)

Answer this question