DataSave Not Working

Hello, I have been using DataSave for a script for a shop system that uses DeveloperProducts to get a currency used for the shop.

I get this error when I try to edit the currency
also when I purchase the Currency it prints it was purchased but nothing
is loaded, even when rejoining.

I also get “502 api HTTP 403” error

note that API services are on

This is how it is set up
Screenshot_17

Script for the Products for buying the currency:

local MarketplaceService = game:GetService("MarketplaceService")

local DataStoreService = game:GetService("DataStoreService")

–PROPERTY OF OMNIGEN DEVELOPMENT

local PreviousPurchases = DataStoreService:GetDataStore("PreviousPurchases")

local TEN_CASH = 501185648

local ONE_HUNDRED_CASH = 501185778

local FIFTY_CASH = 501185715

MarketplaceService.ProcessReceipt = function(receipt)

local ID = receipt.PlayerId…"-"…receipt.PurchaseId

local success = nil

local currency = game.Players.LocalPlayer.PlayerStats.Stats

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 == TEN_CASH then

currency.Value = currency.Value + 10

end

if receipt.ProductId == ONE_HUNDRED_CASH then

currency.Value = currency.Value + 100

end

if receipt.ProductId == FIFTY_CASH then

currency.Value = currency.Value + 50

end

pcall(function()

PreviousPurchases:SetAsync(ID,true)

print("previouspurchases-working")

end)

return Enum.ProductPurchaseDecision.PurchaseGranted

end

end

Script For the DataSave

local DataBaseStore = game:GetService("DataStoreService"):GetDataStore("testing-ds-pixel")

local statsholder = script.Stats

game.Players.PlayerAdded:Connect(function(NewPlayer)

local Key = "Player-ID:" … NewPlayer.userId

local GetSave = DataBaseStore:GetAsync(Key)

local DataBaseFolder = Instance.new("Folder", NewPlayer)

DataBaseFolder.Name = "PlayerStats"

for i, Stats in pairs(statsholder:GetChildren()) do

local NewStats = Instance.new(Stats.ClassName)

NewStats.Name = Stats.Name

NewStats.Value = Stats.Value

NewStats.Parent = DataBaseFolder

end

if GetSave then – dataload

for i, Stats in pairs(script.Stats:GetChildren()) do

DataBaseFolder[Stats.Name].Value = GetSave[i]

print (i, Stats.Name, Stats.Value)

print ("Loaded")

end

else – datasave

local StatsToSave = {}

for i, Stats in pairs (DataBaseFolder:GetChildren()) do

table.insert(StatsToSave, Stats.Value)

print (i, Stats.Name, Stats.Value)

print ("Saved")

end

DataBaseStore:SetAsync(Key, StatsToSave)

end

while wait(15) do --dataautosave

local StatsToSave = {}

for i, Stats in pairs (DataBaseFolder:GetChildren()) do

table.insert(StatsToSave, Stats.Value)

print (i, Stats.Name, Stats.Value)

print ("Saved")

end

DataBaseStore:SetAsync(Key, StatsToSave)

end

game.Players.PlayerRemoving:Connect(function(OldPlayer)

local Key = "Player-ID" … OldPlayer.userId

local StatsToSave = {}

for i, Stats in pairs (DataBaseFolder:GetChildren()) do

table.insert(StatsToSave, Stats.Value)

print (i, Stats.Name, Stats.Value)

print ("Saved")

end

DataBaseStore:SetAsync(Key, StatsToSave)

end)

end)

Just by looking at this I think I see some red flags. Assuming that first script is for each client, when they do purchase a product, and you increment the value of their currency, that updated value of whatever they’re buying would only be visible for that client, and the server will read that data the same before they bought anything, this is due to Filtering, in where you need to call in a RemoteEvent to the server to make changes upon the client’s data. Other than this, I didn’t even think it was possible to define Receipt events in the client, it’d probably be a better bet to do this on the server. That way, you can actually update the player’s currency from that script, with no need for communication via remote events. And I don’t actually know if DataStores reliably work on the client alone, I always thought you could only use them properly from the server. Not sure about this, so I’ll leave this as a thought.

Hope this helps.

May you explain please, would be appreciated

1 Like

I had a hard time analyzing your code, but I don’t blame you for that formatting, it’s quite hard to get it to look right when posting on these forums. :stuck_out_tongue:

I’d recommend you read up on this article that discusses what Filtering is and what you need to do differently. All Roblox games are now forced to use it, so there’s no way to approach this differently, from my knowledge.

I think it is Filtering Compatible, if not what in it makes it not?

I’m basing this on your first script, in where you access the Currency from the LocalPlayer, and in order to get the LocalPlayer it has to be a LocalScript, which only executes on the client. Assuming that first script IS located on the client, then there’s changes that code makes that really the server should be making. Aka, where you set the currency’s value depending on what they buy.