It was working fine yesterday and days before then, I just tested it today and now it doesn't save anything. It also gives off no errors in the output.
local DataStore = game:GetService("DataStoreService") local ds = DataStore:GetDataStore("LeaderboardSaveSystem") local Players = game:GetService("Players") Players.PlayerAdded:Connect(function(player) local key = tostring(player.UserId) local data = ds:GetAsync(key) local leader = Instance.new("Folder") leader.Name = "leaderstats" leader.Parent = player local Speed = Instance.new("NumberValue", leader) Speed.Name = "Speed" local Rebirth = Instance.new("NumberValue", leader) Rebirth.Name = "Rebirth" local GemVal = Instance.new("NumberValue", player) GemVal.Name = "GemVal" local Purchase1 = Instance.new("BoolValue", player) Purchase1.Name = "RedTrail" local success, msg = pcall(function() if data then Speed.Value = data[1] Rebirth.Value = data[2] GemVal.Value = data[3] Purchase1.Value = data[4] else Speed.Value = 0 Rebirth.Value = 0 GemVal.Value = 0 Purchase1.Value = false end end) end) Players.PlayerRemoving:Connect(function(player) local data = { player.leaderstats.Speed.Value, player.leaderstats.Rebirth.Value, player.GemVal.Value, player.Purchase1.Value } local key = tostring(player.UserId) print("player left:", player) ds:SetAsync(key, data) end)
Roblox made a function inside the DataModel class called BindToClose(function)
Here's some notes on the Roblox API about this function.
Description: Schedules the given function to be called when the game is about to shut down.
Note: The purpose of this is to give creators a chance to save data using HttpService or Data Store before the game shuts down.
You can find it on Roblox's API page here: https://wiki.roblox.com/index.php?title=API:Class/DataModel/BindToClose
Above this:
Players.PlayerRemoving:Connect(function(player)
Add this:
game:BindToClose(function() wait(3) print("Done") end)
Note: If your Datastore isn't working on Roblox Studio it might just be an issue with their servers and should only be a problem in your Roblox Studio but will work in online mode on their real servers so test that too.