I am trying to make a save player position script for my obby which saves the player's position when they leave and then puts them there when they join automatically.

This is the first script in Serverscriptservice as a normal script.

game.Players.PlayerAdded:connect(function(player)
	local val = player:WaitForChild("Position")
	player.CharacterAdded:connect(function(char)
		while true do
			wait(1)
			val.Value = char:WaitForChild("HumonoidRootPart").Position
		end
	end)
end)

Then this script is another in the same place but in a different script.

local ds = game:GetService("DataStoreService")
local ds1 = ds:GetDataStore("PositionSavingSystem")

game.Players.PlayerAdded:connect(function(player)
	local val = Instance.new("Vector3Value", player)
	val.Name = "Position"
	
	local userdata	
	pcall(function()
		userdata = ds1:GetAsync(player.UserId)
	end)
	
	if userdata then
		game.Workspace:WaitForChild(player.Name):WaitForChild("HumanoidRootPart").CFrame = CFrame.new(userdata.x, userdata.y, userdata.z)
	else
		ds1:SetAsync(player.UserId, {
			x = 0,
			y = 3,
			z = 0
		})
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	ds1:SetAsync(player.UserId, {
		x = player.Position.Value.X,
		y = player.Position.Value.Y,
		Z = player.Position.Value.Z
		})
end)

The scripts for some reason don't work and the user just spawns at the default spawn point.