I have another script that saves every 2 minutes, so I know that the save script does work. It just doesn't save when someone leaves or the game closes.
local Players = game:GetService("Players") local RunService = game:GetService("RunService") local DS = game:GetService("DataStoreService"):GetDataStore("Data") function save(player) local data = DS:GetAsync(player.UserId) data["tokens"] = player:FindFirstChild("Tok").Value data["combatLogged"] = player:FindFirstChild("CombatLogged").Value DS:SetAsync(player.UserId, data) print("Data Saved!") end Players.PlayerRemoving:Connect(function(player) wait(3) save(player) print("Saved "..player.Name.."'s data!") end) game:BindToClose(function() wait(1) for i, player in ipairs(Players:GetPlayers()) do coroutine.wrap(save)(player) print("Saved "..player.Name.."'s data!") end end)
Remove the wait on both BindToClose and PlayerRemoving. There is a point where the Roblox client/server will not longer respond on shutdown if the client/server was shutdown illegally (Not actually law illegally. But illegal by the computer. Powering off the computer, crashing, task manager, etc)
If you use the ESC menu, and leave the game roblox will correctly save since the client yields on PlayerRemoving. But when you illegally close the application Windows/linux will force stop the application causing it to shutdown quicker than usual.