Note:I created that script in ServerScriptService and I allowed API requests,
My script:
local DS = (game:GetService("DataStoreService"):GetDataStore("sjisjsikjawju"))
game.Players.PlayerAdded:connect(function(plr)
local leaderstats = Instance.new("IntValue",plr)
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue",leaderstats)
cash.Name = "Cash"
cash.Value = 100
local key = ("Id-"plr..UserId)
if DS:GetAsync(key) then
cash.Value = Save[1]
else
local Save = {cash.Value}
DS:SetAsync(key,Save)
end
end)
game.Players.PlayerRemoving:connect(function(plr)
local key = ("Id-"plr..UserId)
local Save = {plr.leaderstats.Cash.Value}
DS:SetAsync(key,Save)
end)
And nothing is saved after I left the game.

1 comment
Or you could simply check this : https://scriptinghelpers.org/guides/saving-and-loading-data-with-datastores