Why the book y axis change?

so i have a code when u put ur mouse over a book the book z axis change by 2
but the y also change tho i didnt make a code that change the y axis


Intrect.Triggered:Connect(function()
	PlayerCamera.CameraType = Enum.CameraType.Scriptable
	toggleHide(1)
	TweenService:Create(PlayerCamera,CameraTween,{CFrame = CameraHere.CFrame}):Play()
	local LastTarget  = nil 
	PlayerMouse.Move:Connect(function()
		local Target =PlayerMouse.Target
		
		if Target then
			if Target.Parent.Name == "Book" and  Target.Parent ~= LastTarget  then
				print(Target,LastTarget)
				LastTarget =  Target.Parent
				local CFrameVAL = Instance.new("IntValue")
				local TargetPosition = Target.Parent:GetPivot().Position
				CFrameVAL.Value =  0
				CFrameVAL:GetPropertyChangedSignal("Value"):Connect(function()

					Target.Parent:MoveTo(TargetPosition - Vector3.new(0,0,CFrameVAL.Value))
					print(CFrameVAL.Value,Target.Position )

				end)
				TweenService:Create(CFrameVAL,CameraTween,{Value = 2}):Play()

				  --z - 2 
			end
		end


	end)
end)

image

1 Like

In this case, you should be using PivotTo() instead of MoveTo() which will actually move the model up when facing obstructions (although in this case there aren’t any).

A more important reason to use PivotTo() is because it moves the pivot of a model, whose position you are using, MoveTo() will use the primary part.

3 Likes

Another reason why using PivotTo is the solution, is because: when you’re changing just an object’s position, the physics engine sees what parts the model is in and if its inside any parts, it moves it above the part it is inside. CFrame movement does not do this.

3 Likes