Two Part Tweening Issues

image


Door Open Vs. Close

The handle is meant to be with the door,(so moving there), and not rotating like on the wrong axis.

local doorGroup = script.Parent
local doorModel = workspace:FindFirstChild("DoorO")
local door = doorModel.Door
local handle = doorModel.Handle
local clickDetector = door.ClickDetector 
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)

local isOpen = false

-- Store initial positions and rotations
local initialDoorCFrame = door.CFrame
local initialHandleCFrame = handle.CFrame

local function openDoor()  
	local openRotation = CFrame.Angles(0, math.rad(90), 0) 

	-- Create tweens for each part
	local doorTween = game:GetService("TweenService"):Create(door, tweenInfo, {CFrame = initialDoorCFrame * openRotation})
	local handleTween = game:GetService("TweenService"):Create(handle, tweenInfo, {CFrame = initialHandleCFrame * openRotation}) 

	-- Play the tweens
	doorTween:Play()
	handleTween:Play()
	isOpen = true
end

local function closeDoor()
	-- Reset to original positions and rotations
	local doorTween = game:GetService("TweenService"):Create(door, tweenInfo, {CFrame = initialDoorCFrame})
	local handleTween = game:GetService("TweenService"):Create(handle, tweenInfo, {CFrame = initialHandleCFrame}) 

	-- Play the tweens
	doorTween:Play()
	handleTween:Play()

	isOpen = false
end

clickDetector.MouseClick:Connect(function()
	if isOpen then
		closeDoor()
	else
		openDoor()
	end
end)```
![image|187x93](upload://k0lJFLWNWmaPDAnHNf04ZMN8Nbf.png)

This is my first time using tweens, this is the reason it's hard for me to do this!
1 Like