Need Some Tweening Help

I have made a script to move a box up and down on the players screen when the click w or s (w = up s = down). It is suppose to stop the Gui at a certain position but it doesn’t stop it while going up.


The Script:

local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")

local Frame = script.Parent:WaitForChild("Frame")
local Player = Frame:WaitForChild("Player")

game:GetService("StarterGui"):SetCoreGuiEnabled(Enum.CoreGuiType.All, false)


UserInputService.InputBegan:Connect(function(Key)
	
	local PosX = Player.Position.X
	local PosY = Player.Position.Y
	
	if Key.KeyCode == Enum.KeyCode.W and Player.Position ~= UDim2.new(PosX.Scale, 0, 0.1, 0) then
		
		Player:TweenPosition(UDim2.new(PosX.Scale, 0, PosY.Scale - 0.4, 0), "Out", "Sine", 0.1, false)
	end
	
	if Key.KeyCode == Enum.KeyCode.S and Player.Position ~= UDim2.new(PosX.Scale, 0, 0.9, 0) then

		Player:TweenPosition(UDim2.new(PosX.Scale, 0, PosY.Scale + 0.4, 0), "Out", "Sine", 0.1, false)
	end
end)