Datastore saves/loads the first stat value as a second stat value

I wanted to learn datastores and stuff like that,but for some reason when i rejoin the value of the second stat becomes the value of the first stat

Heres the script

local ServerStorageRemote = game:GetService("ServerStorage").RemoteData
local DataService = game:GetService("DataStoreService")
local StatsData = DataService:GetDataStore("Statistics")



game.Players.PlayerAdded:Connect(function(player)
	local Lemon = player:WaitForChild("leaderstats").Lemon
	local Yes = player:WaitForChild("leaderstats").Yes
	local playerUID = "Player_" .. player.UserId
	
	local data = {}
	-- Load data
	local success, errormessage = pcall(function()
		data = StatsData:GetAsync(playerUID)
	end)
	
	-- Set data equal to the current stuff
	if success then
		Lemon.Value = data
		Yes.Value = data
		print("Succeeded at loading stuff")
	end
	if errormessage then
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	-- Save
	local Lemon = player:WaitForChild("leaderstats").Lemon
	local Yes = player:WaitForChild("leaderstats").Yes
	local playerUID = "Player_" .. player.UserId
	
	local Saved = {
		Lemon.Value,
		Yes.Value,
	}
	
	
	local didit, errormessage = pcall(function()
		StatsData:SetAsync(playerUID,Lemon.Value)
	end)
	if didit then
		print("Succeeded at saving stuff")
	elseif errormessage then
		warn(errormessage)
	end
end)

Before rejoining:
изображение_2022-08-10_224425720
After rejoining:
изображение_2022-08-10_224513937

How can i fix that?

what is this table for

change this to

local didit, errormessage = pcall(function()
	StatsData:SetAsync(playerUID, Saved)
end)

also this too

Lemon.Value = data[1]
Yes.Value = data[2]
1 Like