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

In-Game Currency Store Client/Server Display Error?

Asked by 6 years ago

Hey! I have a script for developer product, when someone buys one, it gives them a certain amount of "BlauBux". It works in studio, but not Roblox. I have a suspicion that it only works on the game server, and doesnt display on the client's screen, but I'm not sure how to do that!

Here is my code:

local Market = game:GetService("MarketplaceService")
local Store = game:GetService("DataStoreService")

local previousPurchases = Store:GetDataStore("PreviousPurchases")

local Bux100 = 438201037
local Bux500 = 438202156
local Bux1000 = 438202268
local Bux7500 = 438202400
local Bux17000 = 438202528
local Bux50000 = 438202628

Market.ProcessReceipt = function(receipt)

    local Id = receipt.PlayerId.."_"..receipt.PurchaseId

    local success = nil

    pcall(function()
        success = previousPurchases:GetAsync(Id)
    end)

    if success then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end

    local player = game.Players:GetPlayerByUserId(receipt.PlayerId)

    if not player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    else
        if receipt.ProductId == Bux100 then
            game.Players[player.Name].leaderstats.BlauBux.Value = game.Players[player.Name].leaderstats.BlauBux.Value + 100
        end
        if receipt.ProductId == Bux500 then
            game.Players[player.Name].leaderstats.BlauBux.Value = game.Players[player.Name].leaderstats.BlauBux.Value + 500
        end
        if receipt.ProductId == Bux1000 then
            game.Players[player.Name].leaderstats.BlauBux.Value = game.Players[player.Name].leaderstats.BlauBux.Value + 1000
        end
        if receipt.ProductId == Bux7500 then
            game.Players[player.Name].leaderstats.BlauBux.Value = game.Players[player.Name].leaderstats.BlauBux.Value + 7500
        end
        if receipt.ProductId == Bux17000 then
            game.Players[player.Name].leaderstats.BlauBux.Value = game.Players[player.Name].leaderstats.BlauBux.Value + 17000
        end
        if receipt.ProductId == Bux50000 then
            game.Players[player.Name].leaderstats.BlauBux.Value = game.Players[player.Name].leaderstats.BlauBux.Value + 50000
        end
        pcall(function()
        previousPurchases:SetAsync(Id, true)
        end)
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

Thanks in advance!

0
Why are you indexing the Players service just to get the player. You have the player in your hands, why go the extra mile User#24403 69 — 6y
0
You can use player.leaderstats instead of using the Player service. StrategicPlayZ 58 — 6y

Answer this question