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

How do you properly get the DataStore?

Asked by 9 years ago
local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

MarketplaceService.ProcessReceipt = function(receiptInfo) 
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end

    for i, plr in ipairs(game.Players:GetPlayers()) do
        if plr.userId == receiptInfo.PlayerId then

            if receiptInfo.ProductId == id then
            plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value +1000
            end
        end 
    end
    PurchaseHistory:SetAsync(playerProductKey, true)
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

I didn't code this, I've been messing around with a code from the wiki; http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService

I know what it does and what it should do.

When I buy the DevProduct, it shows in console(f9) Cannot access DataStore from this client.

Does anyone know a solution?

Screenshot of error: http://prntscr.com/88yisp

1 answer

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

You should be handling purchases and data store related tasks server-side (not using a LocalScript) -- as mentioned in the article you've got your code from. If you need to communicate the result of your work to the client, you can use a RemoteObject to do so.

1
Thank you very much..... I am happy I learned about these... Now I don't need values for contacting the local screen GUIs legoguy939 418 — 9y
Ad

Answer this question