So I have this CFrame door that makes my game just that much more realistic, but its leaving a big gap in between my the door opened, and the frame of the door, any help?
local cf = script.Parent.Part.CFrame
function onClicked()
if script.IsOpened.Value == false and script.IsOpening.Value == false then
script.IsOpening.Value = true
for i = 1,16 do
script.Parent.Part.CFrame = script.Parent.Part.CFrame * CFrame.new(0, 0, -0.18) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)
wait(0.01)
end
script.IsOpening.Value = false
script.IsOpened.Value = true
elseif script.IsOpened.Value == true and script.IsOpening.Value == false then
script.IsOpening.Value = true
for i = 1,16 do
script.Parent.Part.CFrame = script.Parent.Part.CFrame * CFrame.fromEulerAnglesXYZ(0, 0.1, 0) * CFrame.new(0, 0, 0.18)
wait(0.01)
end
script.IsOpening.Value = false
script.IsOpened.Value = false
script.Parent.Part.CFrame = cf
script.CloseSound:Play()
end
end
script.Parent.Model.Knob2.ClickDetector.MouseClick:connect(onClicked)
Instead of handling it like this, the way I use to handle doors was making an invisible part to act as the door hinge, then placing it as a model, setting the hinge as the primary part, and then rotating the model based on the primary part. The reason I suggest this is you’re also having to account for offset when tweening the door alone, and just guesstimating with a cframe value can get a little frustrating. https://gyazo.com/96c031c1a86b7024532c341ee37f41ae
for i = 1, 50 do
workspace.Teleport1.pivotDoor:SetPrimaryPartCFrame(workspace.Teleport1.pivotDoor.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(2),0)) wait()
end
In-order to get your desired effect, make a pivot point as displayed in the model, on the side you want the door to rotate. Throw both it and the door itself into a model setting the primary part to the pivot point; then in your code you’d simply change