How to rotate part based locally?

I have a door opening system, that opens doors. And the problem I have is with double doors, it opens the door on the left correctly, but the door on the right swings open the wrong way.

-- Open
DoorOpen:Play()

for _, v in pairs(door:GetChildren()) do
	if v.Name == 'Door' then
		print('Door found')
		local Goal = {CFrame = AllHinges[v.Hinge] * CFrame.Angles(0, -math.rad(100), 0)}
		
		local Tween = TweenService:Create(v.Hinge, TweenInfo.new(0.5, Enum.EasingStyle.Bounce), Goal)
		
		Tween:Play()
	end
end

So how can I open both doors correctly based on their current orientation?

Hinge works like so


Just a small part welded to the door

Maybe one door could rotate negatively and other not? I think that’s because of how you set the door rotation.

How can I tell what door to rotate which way? I can’t rename the door either, both doors have to be named ‘Door’

Maybe one door could be named Door1 and the other Door2. Could you explain me why you can’t change the name?

The doors have to be named ‘Door’ because at the start I have to go through every building/room and collect the doors from there. Changing the doors names would require me to go through every single models door and changing the name + changing a bunch of the code

1 Like

What I do on my game is I have a configuration folder for each door and have a number value for a open angle and close angle. So depending on how you want your door to swing it will work however you want. In your door script just read their own values.

The simple solution, if your door is symmetrical in that direction, is rotating the door to be upside-down.

I’m not quite sure what you mean here?

I don’t want to have to insert a value into every single door in the game tho. I want a way for the script to just know if the doors on the left or the right based on its position or something

If you were to take your left door, duplicate it, and turn it upside-down so that the front is still facing you, the door would open the right way. The only problem is, the whole model would be upside-down, and the easiest way to fix that is to flip all the decorations to line up with the left door.

Flipping the door does nothing, still opens the same way

If don’t want to manually set values I guess you could check if the hinge is at a negative offset or positive offset from the door’s center position and based on that open it differently.

Rotate the hinge on the other door by 180 degrees, basically flip it top to bottom, upside down. See if that does anything

local function ToggleDoor(Dir)
	TweenService:Create(v.Hinge, TweenInfo.new(0.5, Enum.EasingStyle.Bounce), {CFrame = AllHinges[v.Hinge] * CFrame.Angles(0, math.rad(100) * (Dir or 1), 0)}):Play()
end

for _, Object in next, Doors:GetChildren() do
	if Object.Name == 'Door' then
		ToggleDoor() -- Identify if it's a left or right door and put -1 as a parameter for a left door and 1 as a parameter for the right door
	end
end