Hello, I have a simple Leaderstats script with save system in it.
How ever when player exits the game, event doesn’t fires.
The script is not local script.
And of course accessing the data is enabled in settings.
Script:
local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("V1.0")
game.Players.PlayerAdded:Connect(function(plr)
local Stats = Instance.new("Folder")
Stats.Name = "leaderstats"
Stats.Parent = plr
local Record = Instance.new("IntValue")
Record.Name = "Record"
Record.Parent = Stats
Record.Value = ds:GetAsync(plr.UserId, plr.leaderstats.Record.Value) or 0
local Score = Instance.new("IntValue")
Score.Name = "Previous"
Score.Parent = Stats
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId, plr.leaderstats.Record.Value)
print("DataSaved")
end)