Need Help With DataStore Saving

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.

Hey, I’ve already made a post about this topic, hope it helps you.

DataModel | Roblox Creator Documentation. Here is your fix! :slight_smile: