Tweening a Door Issues

local doorGroup = script.Parent
local doorModel = workspace:FindFirstChild("DoorO")
local door = doorModel.Door
local hinge = doorModel.Hinge -- Assuming this is your hinge part
local clickDetector = door.ClickDetector
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local isOpen = false

-- Calculate hinge offset based on hinge position relative to door
local hingeOffset = door.CFrame:Inverse() * hinge.Position 

-- Store initial positions and rotations (Adjusted for Hinge)
local initialDoorCFrame = door.CFrame * CFrame.new(hingeOffset) 

local function openDoor()
	local openRotation = CFrame.Angles(0, math.rad(90), 0) * CFrame.new(hingeOffset) 
	local doorTween = game:GetService("TweenService"):Create(door, tweenInfo, {CFrame = initialDoorCFrame * openRotation})
	doorTween:Play()
	isOpen = true
end

local function closeDoor()
	local doorTween = game:GetService("TweenService"):Create(door, tweenInfo, {CFrame = initialDoorCFrame})
	doorTween:Play()
	isOpen = false
end

clickDetector.MouseClick:Connect(function()
	if isOpen then
		closeDoor()
	else
		openDoor()
	end
end)

This is my first time tweening really.
I need to solve these issues:

  • Door just falling(due to being unanchored)
  • Door not turning properly(Goes in ground, and doesn’t rotate around the proper side of the hinge(I want it to turn in reverse, or on the other side)
    image
2 Likes

The following tutorial covers it:

For the door falling I’d use a weld constraint if you haven’t tried! I’m not sure about the other issues, but that could help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.