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

Is there a way to remember Dev Product Purchases?

Asked by 10 years ago

I was wondering if you could poissibly store dev product purchases so once they have been purchased they stay with you forever, like if they buy a sword, when they come back the game would recongnise it and give them the sword. I can't create gamepasses cause my game seems to be broken so I cant create a single pass. I was thinking maybe Data Store. I have looked at the dev product wiki but need help with server side and putting in the datastote.

-- Server side
local MarketplaceService = Game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo)
    game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId
    -- ...
    -- use DataStore to record purchase
    -- ...  
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
-- Client side
local MarketplaceService = Game:GetService("MarketplaceService")
local buyButton = game.Workspace.BuyButton.SurfaceGui.TextButton
local productId = "ID"

buyButton.MouseButton1Click:connect(function()
    MarketplaceService:PromptProductPurchase(player, productId)
end)

1 answer

Log in to vote
2
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

So basically, you are wanting to use the DataStore to record that a specific user has a specific item.

First you need to create a DataStore.

local DataStore = game:GetService("DataStoreService"):GetDataStore("ProductPurchases")

Recording the purchase:

local key = "userId" .. tostring(userId) .. "_productId" .. tostring(productId)
DataStore:SetAsync(key, true)

Now when you're checking if the user has the product, you need to form the same key and use DataStore:GetAsync(key). It will return nil if the key hasn't been set yet.

local key = "userId" .. tostring(userId) .. "_productId" .. tostring(productId)
if DataStore:GetAsync(key) == true then
  print("Player bought the product")
end
0
in localscript, startergui? NinjoOnline 1146 — 10y
0
DataStores can only be accessed from server scripts. Merely 2122 — 10y
0
which are just normal scripts, placed just in sevrerscriptstorage? NinjoOnline 1146 — 10y
0
Normal scripts are server scripts. Merely 2122 — 10y
0
ok thanks :D NinjoOnline 1146 — 10y
Ad

Answer this question