Having trouble with CFrames

Hello Developers!. Recently I have been working on many different Mini-games to improve my skill-set.
I have started working on a Whac-A-Mole type game, I have un-anchored and welded all my parts to one main part.
and when I try tween it downwards by -1 on the Y axis it works quite well,However when I try tween up the model by adding

  • 1 back on the Y axis it is completely twisted, I’m not sure why this is the case.

GIF::
https://gyazo.com/6a8200d92aef1107d56b506435eba979

local function DiglettTween(mainpart)
	
local TweenService = game:GetService("TweenService")	
local tInfo = TweenInfo.new(1,Enum.EasingStyle.Elastic,Enum.EasingDirection.Out)
	
local X = mainpart.CFrame.X	 --0.161
local Y = mainpart.CFrame.Y - 1
local Z = mainpart.CFrame.Z		
	
local goals = {}	
goals.CFrame = CFrame.new(X,Y,Z)
	
local Y2 = mainpart.CFrame.Y + 1	
local Goals2 = {}	
Goals2.CFrame = CFrame.new(X,Y2,Z)	
	
local Tween1 = TweenService:Create(mainpart,tInfo,goals)
local Tween2 = TweenService:Create(mainpart,tInfo,Goals2)
	
	if mainpart.CFrame.Y > 1.555 then
		print("We need to Tween Down")
		Tween1:Play ()
	else
	Tween2:Play ()
	 print("We need to Tween Up")
	end	
	
end
1 Like

Yeah in order to Tween the model I need to use CFrame instead of Position.

My mistake, can you check the orientation of the model after the CFrame moves it up? I believe the rotation matrices default to 0 if they are unspecified

This happens because you’re setting a new CFrame to a part. the orientation is set to 0 you can define the orientation doing this:
CFrame.new(X,Y2,Z) * CFrame.Angles(0,math.rad(90),0)
This might not be the exact Orientation of the part but try playing with them till you get the exact orientation

1 Like

Really appreciate the help man. Its’ working well now.