Data isn't saving, Why?

plus you should update the script in the beginning for more understanding

Wdym by update the script at the beginning?

when you first created the post update that

I tried seeing if it works in game but it doesn’t save and I checked console It printed Data saved message with no errors…

hmm, time to spoon feed since nothin i can do :slight_smile:

local SAS = game:GetService("DataStoreService"):GetDataStore("SavingAllStats")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local Deaths = Instance.new("IntValue", leaderstats)
	Deaths.Name = "Deaths"
	Deaths.Value = 0
	local Kills = Instance.new("IntValue", leaderstats)
	Kills.Name = "Kills"
	Kills.Value = 0
	local Panies = Instance.new("IntValue", leaderstats)
	Panies.Name = "Panies"
	Panies.Value = 0
	local DKSaved = nil
	pcall(function()
		DKSaved = SAS:GetAsync(player.UserId)
	end)
	if DKSaved ~= nil then
		Deaths.Value = DKSaved.deaths
		Kills.Value = DKSaved.kills
		Panies.Value = DKSaved.panies
		print("Balls :)")
	else
		Deaths.Value = 0
		DKSaved.Value = 0
		Kills.Value = 0
		print("New Player")
	end
	player.CharacterAdded:Connect(function(char)
		local Human = char:WaitForChild("Humanoid")
		Human.Died:Connect(function()
			player.leaderstats.Deaths.Value += 1
			local Tag = Human:FindFirstChild("creator")
			local Killer = Tag.Value
			if Tag and Killer then
				Killer.leaderstats.Kills.Value += 1
			end
		end)
	end)
end)

game.Players.PlayerRemoving:Connect(function(player)
	local UserId = player.UserId
        local saveData = {
        deaths = player.leaderstats.Deaths.Value,
        kills =  player.leaderstats.Kills.Value,
        panies =  player.leaderstats.Panies.Value
	local leaderstats = player:WaitForChild("leaderstats")
	local saved, err = pcall(function()
                SAS:SetAsync(UserId, saveData)
        end
        if saved then print('data saved') else warn(err) end
         

end)

here ya go mah boi, not the recommended saving method but it works. On the first save in studio it will for sure error, and then after setting the value it will work the second time. Reminder, this only happens in studio. It should work everywhere else just fin

2 Likes

I actually got the answer yesterday from someone, But this is the exact same way on how he helped me, Thank you! I will put it as a solution incase anyone runs into it. Thanks again!

No problem, glad you found the answer. I am sorry for my late reply, as I was out at a party that time