How would I make it better? Because as you can see it doesn’t work perfectly
The script:
local TS = game:GetService("TweenService")
local button = script.Parent
local door = game.Workspace.DoorModel.Door
local bar = game.Workspace.DoorModel.Bar
local doorCF = door.CFrame
local isOpen = door.IsOpen
----------------------
button.MouseClick:Connect(function(plr)
if isOpen.Value == false then
isOpen.Value = true
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local goal = {CFrame = CFrame.new(bar.Position) * CFrame.Angles(0, math.rad(120), 0) * CFrame.new(0, 0, 7.015)}
local tween = TS:Create(door, info, goal)
tween:Play()
else
isOpen.Value = false
local info = TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local goal = {CFrame = doorCF}
local tween = TS:Create(door, info, goal)
tween:Play()
end
end)
Add a part at the point you want the door to rotate around. Add a weld between it and the door. Now Tween the hinge part instead of the door. Make sure the hinge is anchored and the door is unanchored, so the weld will work.
EDIT: That was very confusing. I worded that very poorly. But, the link @InherentBalance shared does basically the same thing, but explains much better.