local DataStore = game:GetService(“DataStoreService”):GetDataStore(“CurrencyDataStore”)
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = currencyName
currency.Parent = folder
local ID = currencyName.."-"..player.UserId
local savedData = nil
pcall(function()
savedData = DataStore:GetAsync(ID)
end)
if savedData ~= nil then
currency.Value = savedData
print("Data loaded")
else
-- New player
currency.Value = 100
print("New player to the game")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local ID = currencyName…“-”…player.UserId
DataStore:SetAsync(ID,player.leaderstats[currencyName].Value)
end)
game:BindToClose(function()
-- When game is ready to shutdown
for i, player in pairs (game.Players:GetPlayers()) do
if player then
player:Kick("This game is shutting down")
end
end
wait(5)
Im testing on Studio But it saves other things like if i collect coins, but if i buy in game currency against robux it wont give the amount that i order it gives only this warning messages ![Screenshot_3|690x75]
Well, the key doesn’t square with the datastore key, which is saved by the script you gave. I guess the player_364498109 key is saved in another script. Could you please show the code that saves the printed key?
I mean, are you saving or getting the data key? If so, how often does it get the key? Quick requests may slow down the datastores to get the key. There is a cooldown of approximately 6 seconds for each request. Try checking your other scripts that use datastores.