My cframe door is currently leaving a gap?

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

2 Likes

So your saying I weld a door part to a small block part?

1 Like

I didn’t use any welding, I simply place both parts in a independent model,
https://gyazo.com/d1f72745d7bf3dadbaf8465175b20906
setting the properties accordingly,
https://gyazo.com/ed377dbae91db4c465a5775fb9b418bf
and run code similar to

for i = 1, 50 do
workspace.Teleport1.pivotDoor:SetPrimaryPartCFrame(workspace.Teleport1.pivotDoor.PrimaryPart.CFrame * CFrame.fromEulerAnglesXYZ(0,math.rad(2),0)) wait() 
end

Would it be possible to send me a model link so I could have a look at this for myself?

DoorModel.rbxm (2.7 KB)

3 Likes

Im still stumped, how would I replicate this for my script?

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

script.Parent.Part.CFrame = script.Parent.Part.CFrame * CFrame.new(0, 0, -0.18) * CFrame.fromEulerAnglesXYZ(0, -0.1, 0)

to

script.Parent.ModelName:SetPrimaryPartCFrame(script.Parent.ModelName.CFrame * CFrame.fromEulerAnglesXYZ(0, -0.1, 0))

If you need anymore assistance I’d gladly walk you through it in a team create or what not.