Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I change the rotation of this model using ":GetPrimaryPartCFrame" for a door?

local Door = script.Parent.Parent.Parent
local mainPart = script.Parent.Parent.Parent.Union
local Handle = script.Parent



local openDoor = false
Handle.ClickDetector.MouseClick:Connect(function()
	if openDoor == false then
		for i = 1, 13 do
			Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame(Vector3.new(-6.152, 3, -8.748)) * CFrame.Angles(0,math.rad(-i),0))
			wait(0.01)
		end
		openDoor = true
	end
end)

The problem I'm having is when I click the handle it rotates the door, but I also want it to move as well, so the door looks realistic and isn't just rotated in the middle of the doorway.

1 comment

0

GetPrimaryPartCFrame() returns the CFrame of the PrimaryPart in the model. (The same as Model.PrimaryPart.CFrame, If you've set a primaryPart.) you've placed a Vector3.new() inside of it, that won't do a thing.

1 answer

✓ Accepted answer

The easiest way to achieve this is to set the PrimaryPart of the door to a part that will act as the hinge of the door. You can do this by creating an invisible part inside of the door model that is positioned at the edge of the door, and then setting the PrimaryPart to that invisible part. As the door rotates relative to the PrimaryPart when using SetPrimaryPartCFrame, the rest of the door will rotate relative to the hinge part, creating the opening effect.

If you called the part that you wanted to rotate it relative to Hinge, you could put this on the second line of your script:

Door.PrimaryPart = Door:FindFirstChild("Hinge",true)

Otherwise, you can just set the PrimaryPart manually in the properties window.

This discussion is preserved as it was. New answers, comments, and votes are closed.