How do I make a door rotate when triggered?

Hello, I’m making a keycode door where the door opens when the right code is entered. I can’t seem to make the door rotate. This is what I’m trying to rotate it to:


Here is the script I used for the enter button that should (hopefully) trigger it.

db = false
script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if db == false then
		db = true
		script.Parent.Position = script.Parent.Position + Vector3.new(0.05,0,0)
		script.Parent.Beep:Play()
		if script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text == script.Parent.Parent.Code.Value then
			game.Workspace.Door1.Activate.Value = true
			script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text = "CORRECT"
		else
			script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text = "INCORRECT"
		end
		wait(0.1)
		script.Parent.Position = script.Parent.Position - Vector3.new(0.05,0,0)
		wait(2)
		script.Parent.Parent.CodeShower.SurfaceGui.TextLabel.Text = ""
		db = false
	end
	
end)

Inside the door model, I placed a BoolValue named “Activate” which is set to true once the correct code is entered. Please note that prior to this, I tested it with a door with a single part that sets collision to off so you can walk through it once the code is entered. I built a door, grouped it as a model, now I don’t know what to do since there’s a bunch of parts. Here is the script I placed under the BoolValue:

local model = script.Parent.Parent
local Pivot = model:GetPivot()
script.Parent.Parent:WaitForChild("Activate")
while true do
	if script.Parent.Value == true then
		task.wait()
		Pivot *= CFrame.Angles(0,math.rad(25),0)
		wait(0.1)
		Pivot += CFrame.Angles(0,math.rad(25),0)
		wait()
		script.Parent.Value = false
	end
end

Inside the model, I also put this:

local model = script.Parent
model.PrimaryPart = script.Parent.Main

Main contains all the detailed parts of the door. Any help is appreciated, thank you.

You can’t multiply CFrame.Angles like that to the pivot. You can get the CFrame of the primary part instead once you weld all the parts in the door to it

1 Like

This will just snap the door open and closed.
Google “roblox make a tween door” or use the Search tool up above with “tween door” to make a smooth opening door.

How did I not realise the snapping :skull:

Hello, I’ll look it up, thank you! If you don’t mind, I’d like to ask about the build as well since I saw your builder tag.

What should I do with the small details on the main door? I’ve just placed them inside, but should I make a union, or something, before I tween the door? Thank you.

Tween the Anchored door hinge Part and Weld all the other door Parts, Unions and details to the hinge Part.

1 Like

Thank you! characterrrm inumum

1 Like