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 wins = Instance.new("NumberValue") wins.Name = "Wins" wins.Parent = leaderstats local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-Wins") end) if success then wins.Value = data else print("data failed") warn(errormessage) end end) game.Players.PlayerRemoving:Connect(function(player) local success, errormessage = pcall(function() myDataStore:SetAsync(player.UserId.."-Wins", player.leaderstats.Wins.Value) end) if success then print("data saved") else print("data failed") warn(errormessage) end end)
When I open up the Explorer tab, and find the value and change it in the Properties window, it does not save, even when it prints, "data saved". It also does not save when I update the value in the Command Bar. Why is that, and how can I resolve this error?
Hi I am not sure this will work but you can try it:
where you have this set of code:
local data local success, errormessage = pcall(function() data = myDataStore:GetAsync(player.UserId.."-Wins") end) if success then wins.Value = data else print("data failed") warn(errormessage) end
change to this:
local success,data = pcall(function() return myDataStore:GetAsync(player.UserId.."-Wins") end) if success and data then wins.Value = data else print("data failed") warn(errormessage) end