I'm making a game where you put tix in a tip jar. This is supposed to save, so if you join a server and there is 5 tix in the jar, there would still be 5 tix in the jar when you rejoin. You can put more tix in the jar by buying the developer product. The developer product works as expected. The PurchaseHistory data store works as well. The problem lies in the "Tix" data store. There is nothing in the output when I use 'Play Solo', yet it doesn't do as expected. In fact, it doesn't do anything at all. Buying the developer product doesn't put tix in the jar.
local productId=21888277 local dsph=game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local MarketplaceService = game:GetService("MarketplaceService") dst=game:GetService("DataStoreService"):GetDataStore("Tix") MarketplaceService.ProcessReceipt=function(receiptInfo) for i,player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.userId then if receiptInfo.ProductId==productId then dst:IncrementAsync("tixKey",1) value=dst:GetAsync("tixKey") end end end playerProductKey = "p_".. receiptInfo.PlayerId.."_p_"..receiptInfo.PurchaseId dsph:IncrementAsync(playerProductKey,1) return Enum.ProductPurchaseDecision.PurchaseGranted end if dst:GetAsync("tixKey")~= nil then for i=1,value do local clone=game.Workspace.toast:Clone() clone.Parent=workspace clone.CFrame=CFrame.new(7.331,6.38,1.63) end end
Thanks in advance!
Well the problem here is that you're never setting the 'tixKey' in the first place. You're attempting to GetAsync of a value that was never stored, and with your conditional for checking if it's not nil makes it return no error, in case you were confused about that.
Also, you're not attempting to access the 'tixKey' from any particular player, so you're going to have to set a key with the player's userId
So what you're going to have to do is attempt to GetAsync of the 'tixKey', check if it's nil.. if it is nil then use SetAsync to set it. And if it's not nil then use UpdateAsync to update the current value.
I can'y make an exact script for you considering the circumstances, but I hope you can manipulate this to your use.
Example;
local productId=21888277 local dsph = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local MarketplaceService = game:GetService("MarketplaceService") local dst=game:GetService("DataStoreService"):GetDataStore("Tix") MarketplaceService.ProcessReceipt = function(receiptInfo) for i,player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.userId then if receiptInfo.ProductId == productId then local val = dst:GetAsyc("tix_"..player.userId) if val == nil then dst:SetAsync("tix_"..player.userId, 1) else dst:UpdateAsync("tix_"..player.userId,function(oldVal) return oldVal + 1 end) end end end end playerProductKey = "p_".. receiptInfo.PlayerId.."_p_"..receiptInfo.PurchaseId dsph:IncrementAsync(playerProductKey,1) return Enum.ProductPurchaseDecision.PurchaseGranted end
I hope this works for you, if not then feel free to PM me.