Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a CFrame rotating door?

Asked by 7 years ago

Hello, i need some help in creating a CFrame door, when the door rotate just like irl.

Thank you if you could help.

1 answer

Log in to vote
0
Answered by
mattscy 3725 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

If you wanted to use CFrame to rotate the door, the simplest way is by using SetPrimaryPartCFrame to rotate the door relative to a part in the door that acts as a hinge.

To do this, you would make the door into a model that consists of the door part and a part that is located towards the side of the door at the location you wanted to rotate it relative to.

For this example, the door part would be called Door and the part that will act as the hinge would be called Hinge. This script would go inside the door model and activate when the door is clicked.

local sp = script.Parent
sp.PrimaryPart = sp.Hinge
local debounce = true
local open = false
local speed = 1

local cd = Instance.new("ClickDetector")
cd.Parent = sp.Door

cd.MouseClick:Connect(function(hit)
   if debounce then
      debounce = false
      if open then
         open = false
         for i = 1,90/speed do
            sp:SetPrimaryPartCFrame(sp.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(1*speed),0)
            wait()
         end
      else
         open = true
         for i = 1,90/speed do
            sp:SetPrimaryPartCFrame(sp.PrimaryPart.CFrame * CFrame.Angles(0,math.rad(-1*speed),0)
            wait()
         end
      end
      debounce = true
   end
end)
0
Thank you so much, helped a lot! oliwierpl11alt 20 — 7y
Ad

Answer this question