local dss = game:GetService("DataStoreService")
local data = dss:GetDataStore("Data")
game.Players.PlayerAdded:Connect(function(plr)
local folder = Instance.new("Folder", plr)
folder.Name = "leaderstats"
local coins = Instance.new("IntValue", folder)
coins.Name = "Coins"
print("Sucess!")
local pd
local success, errormessage = pcall(function()
pd = data:GetAsync(plr.UserId.."-coins")
end)
if success then
coins.Value = pd
else
print("There was an error")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
data:SetAsync(plr.UserId.."-coins", plr.leaderstats.cash.Value)
end)
if success then
print("Player's Data has been saved!")
else
print("Player's Data has not been saved!")
warn(errormessage)
end
end)
but it printed "Players data hasn't been saved!"

15 comments
Make sure you have studio access to API services like DataStore in your game settings.
How do i check that?
Im a beginner i just learned datastores by alvin Blox
home tab-game settings-options
Ohhhhhh Thankyou so much.
np, as a general rule whenever I start up a new project i immediately enable studio access to api services
It still says Player's Data has not been saved! 14:36:57.680 - cash is not a valid member of Folder
Hi, check this out - https://developer.roblox.com/en-us/articles/Saving-Player-Data ////// in the script in there change the money part into the name of your currency.
in line 29 you said plr.leaderstats.cash.Value instead of plr.leaderstats.coins.Value
I've read that multiple times before.
Ok it doesn't warn me of any error message but how do i test it to make sure it really works
You can just press play in Roblox Studio, change your Coins value on the server, and then hit 'Stop', it'll tell you if it saved by printing out your success message, and if you play it again your Coins should be the same. You can do it inside of Roblox Studio.
But what if i play it again and the value is 0?
Well, first of all make sure to change it on the server. And if it didn't work then it should print out your error message.
I still dont get it