I have this leadestats script with saving using datastores but it doesn’t save and always warn me that there was an error saving the data which i scripted so that i know that it doesn’t save
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game:GetService("Players").PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Level = Instance.new("IntValue")
Level.Name = "Level"
Level.Parent = leaderstats
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = plr
local data
local cash
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-Level")
cash = myDataStore:GetAsync(plr.UserId.."-Cash")
end)
if success then
Level.Value = data
Cash.Value = cash
else
warn(errormessage)
print("There was an error saving data")
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
myDataStore:SetAsync(plr.UserId.."-Level", plr.leaderstats.Level.Value)
myDataStore:SetAsync(plr.UserId.."-Cash", plr.Cash.Value)
end)
if success then
print("Player's Data successfully saved")
else
print("There was an error saving the data")
wait(errormessage)
end
end)
You can just create another folder, and have your cash stored in there (the name should be something other then leaderstats). I think its cleaner then having it directly in the player. Anyways can you answer the above question.
I don’t think theres anything wrong with your code. Make sure you have your API services on. Also, since your cash is not a parent of leaderstats it wont show on the tab thingy.
However it still exists. Not sure why you’re getting those errors.
This is not what I mean, if you are testing from the studio and if you press the stop button the game will suddenly close and your actions will not be performed.