Datastore doesn't save new created Values

Hello,
I want to make a script, that creates a StringValue, and then after quitting it saves the value. The script can create a value, but as soon as I quit, and rejoin, the value is deleted.

Here is my datastore script:

local DatastoreService = game:GetService("DataStoreService"):GetGlobalDataStore()

game.Players.PlayerAdded:Connect(function(plr)
	local Datastore = DatastoreService
	local Key = plr.UserId .."_Saves"
	local Data = Datastore:GetAsync(Key)
	if Data then
		for i, v in ipairs(Data) do
			if plr.savestats:FindFirstChild(v[1]) then
				plr.savestats:FindFirstChild(v[1]).Value = v[2]
			end
		end
	end
	
	
	game.Players.PlayerRemoving:Connect(function(plr)
		local Key = plr.UserId .."_Saves"
		local data = {}
		for i, v in ipairs(plr.savestats:GetChildren()) do
			if v.Name ~= "Hunger" then
				table.insert(data, {v.Name, v.Value})
			end
		end

		Datastore:UpdateAsync(Key, function(pastData)
			return data
		end)

	end)
end)

Here is the script of the button which creates the value:

local plr = game.Players.LocalPlayer
local rs = game:GetService("ReplicatedStorage")
local saves = rs.RemoteEvents.CreateSave

script.Parent.MouseButton1Up:Connect(function()
	if not script.Parent.Parent.SaveName.Text:match("^%s*$") then
		local name = plr.PlayerGui.Saves.CreateSave.SaveName.Text
		saves:FireServer(name)
	else
		script.Parent.Parent.Error.Visible = true
		wait(1)
		script.Parent.Parent.Error.Visible = false
	end
	
end)

And here is my serverscript, where the remote event fires:

local rs = game:GetService("ReplicatedStorage")
local saves = rs.RemoteEvents.CreateSave

saves.OnServerEvent:Connect(function(plr,name)
	local newsave = plr:WaitForChild("savestats").LobbySave --This works fine
	newsave.Value = name
	newsave.Parent = plr:WaitForChild("savestats")
	
	local oldsave = Instance.new("StringValue")
	oldsave.Value = name
	oldsave.Parent = plr:WaitForChild("savestats")
	
	local lastsave = game.ReplicatedStorage.Gui.SavesTemp.Save:Clone()
	lastsave.Text = oldsave.Value
	lastsave.Parent = plr.PlayerGui.Saves.LastSaves.ScrollingFrame
end)

Thanks to everyone who is helping me!
~ Maini

Try moving the Players.PlayerRemoving connection outside of the function for the Players.PlayerAdded event.

The last script I sent was the wrong one, I updated it. So the “newsave” value saves, but the “oldsave” value doesn’t save.

You should still move the Players.PlayerRemoving connection to the top level.

Okay, I tried it, but only the “newsave” Value is saving, the “oldsave” Value still isn’t saving.

You should update oldsave before updating newsave.

That sadly doesn’t work either