Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you properly get the DataStore?

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

✓ Accepted answer

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 comment

1

Thank you very much..... I am happy I learned about these... Now I don't need values for contacting the local screen GUIs

This discussion is preserved as it was. New answers, comments, and votes are closed.