code here btw verry sloppy code cause im bad at scripting
local Datastore = game:GetService("DataStoreService")
local MyData = Datastore:GetDataStore("FQ34FFHH44L3")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = "Gold"
cash.Parent = leaderstats
local data
local sucsess ,errormessage = pcall(function()
data = MyData:GetAsync(player.UserId.."-cash")
end)
if sucsess then
cash.Value = data
else
print("there was a error saving")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local sucsess, errormessage = pcall(function()
MyData:GetAsync(player.UserId.."-cash",player.leaderstats.gold.value)
end)
if sucsess then print("player data saved succsefully")
else
print("There was a error")
warn(errormessage)
end
end)

5 comments
It still doesnt work but i think it would be easyer if u could acces the output add me on rblx and i will add u in a teamcreate
Here is an example I just typed up for you. Im pretty sure there are also some minor errors throughout the script: https://pastebin.com/2Z3X6USG
Its private
my bad
fixed^