Door moves position when trying to rotate it

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to rotate a door (part) on an attachment.

  2. What is the issue? Include screenshots / videos if possible!
    It is a Rust Building System and the door comes from replicated storage from a script, but when i click on it, the door moves positions to where it would originally be in replicated storage, not at its current position. Here’s a video :

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried Devforum and YT

Heres my simple code to rotate it

local door = script.Parent.Parent
local attachment = script.Parent.Parent.DoorSnapAttachment

function OpenDoor()
	door.CFrame = CFrame.Angles(0,90,0)
end

script.Parent.MouseClick:Connect(function()
	OpenDoor()
end)

The position of the CFrame “CFrame.Angles(0,90,0)” is 0,0,0. Try this instead:

function OpenDoor()
	door.CFrame *= CFrame.Angles(0,math.pi/2,0)
end

function CloseDoor()
	door.CFrame *= CFrame.Angles(0,-math.pi/2,0)
end

Also CFrame angles is measured in radians so instead of 90 use math.pi/2

1 Like

ok, thanks it worked, but It looks like this now

oh wait, its now 90 degrees, its good, but it doesnt move along the attachment

You need to make the door into a model, with the primary part set to a part which is on the side of the door to act like a hinge. Anchor the hinge part and unanchor the door part, and create a weld constraint between the hinge part and the door part. Then instead of modifying the cframe of door modify the cframe of the hinge part.

1 Like

I kinda cant make another part in the situation im in, cus of the way the placement system is made, I need it to rotate on an attachment, there is one attachment in the door and another attachment in a doorframe and both attachments are at the same position