Any points gained between the player joining the game and the server shutting down is lost, id there a fix?
local dataStoreService = game:GetService("DataStoreService")
local myDataStore = dataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local Score = Instance.new("IntValue")
Score.Name = "Score"
Score.Parent = leaderstats
local Credits = Instance.new("IntValue")
Credits.Name = "Credits"
Credits.Parent = leaderstats
local data
local data2
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(player.UserId.."-Credits")
data2 = myDataStore:GetAsync(player.UserId.."-Score")
end)
if success == true then
Credits.Value = data
Score.Value = data2
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage pcall(function()
myDataStore:SetAsync(player.UserId.."-Credits", player.leaderstats.Credits.Value)
myDataStore:SetAsync(player.UserId.."-Score", player.leaderstats.Score.Value)
end)
if success == true then
print ("Data successfully saved")
else
print ("Error")
warn(errormessage)
end
end)

3 comments
What is the error traceback?
Well when I save in studio client it comes up with error, but data saves fine in game. It only loses when i shut down the game.
Give my answer a look.