local DataStoreService = game:getService("DataStoreService")
local deathsDataStore = DataStoreService:GetDataStore("DeathSaveSystem")
game.Players.PlayerAdded:connect(function(player)
local leader = Instance.new("Folder", player)
leader.Name = "leaderstats"
local Deaths = Instance.new("IntValue", leader)
Deaths.Name = "dies"
Deaths.Value = deathsDataStore:GetAsync(player.UserId)
end)
game.Players.PlayerRemoving:Connect(function(player)
deathsDataStore:SetAsync(player.UserId, player.leaderstats.dies.Value)
end)
DataStore isnt saving on PlayerRemoving
In studio, there usually isn’t enough time for any function connected to PlayerRemoving to fully execute, and yielding functions like :SetAsync() especially won’t have enough time before the game stops. Try kicking the player during the play test instead of stopping. Then wait a bit and then stop the game.
caviarbro
(caviarbro)
August 21, 2021, 11:26pm
3
Hey, I’ve already made a post about this topic, hope it helps you.
Hey, I see few problems with it.
First you are using new datastore for everything, while DataStore can handle up to 4MB of data.
You are using SetAsync over UpdateAsync.
local DSS = game:GetService("DataStoreService")
local dataStore = DSS:GetDataStore("DataStore")
local Players = game:GetService("Players")
local mainTable = {
Coins = {DefaultValue = 100, Folder = "leaderstats",ValueType = "NumberValue"},
Money = {DefaultValue = 0, Folder = "Stats",ValueType = "StringValue"},
}
local …