CFrame & Hinges

I am pretty clueless on how to tween a door around a hinge, door works perfectly just does not move around the hinge.

local TweenService = game:GetService("TweenService")

local model = script.Parent
local first = model.First.Union
local prompt = model.Card1.Detector1.Attachment.ProximityPrompt

local tweenInfo = TweenInfo.new(1)

local Open = {}
local Closed = {}

Open.CFrame = first.CFrame * CFrame.Angles(0, math.rad(90), 0)
Closed.CFrame = first.CFrame

local Open = TweenService:Create(first, tweenInfo, Open)
local Closed = TweenService:Create(first, tweenInfo, Closed)

prompt.Triggered:Connect(function(player)
	if prompt.ActionText == "Close" then
		Open:Play()
		prompt.ActionText = "Open"
	else
		Closed:Play()
		prompt.ActionText = "Close"
	end
end)

I looked up about it and still pretty clueless…

Is the hinge a primary part in your model?

it is currently in a separate model inside the the door model

It needs to be like this:

Closed.CFrame = first.CFrame
Open.CFrame = first.CFrame * CFrame.Angles(0, math.rad(90), 0)

ah, alright, if I were to set the a part in the model, would it automatically be used as a hinge or would I need to set it up in the script first?

This is my script you can use it if you want, its better i think.

local model = script.Parent
local first = model.PrimaryPart
local prompt = model.Card1.Detector1.Attachment.ProximityPrompt

local opened = false

function OpenDoor()
	if opened == false then
		opened = true
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(first.CFrame*CFrame.Angles(math.rad(5), 0, 0))
			wait()
		end
	else
		opened = false
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(first.CFrame*CFrame.Angles(math.rad(-5), 0, 0))
			wait()
		end
	end
end

prompt.Triggered:Connect(OpenDoor)

Not sure if this is any help but you could achieve a hinge effect with the new pivot system:

  1. Set the Models PrimaryPart to your hinge

  2. Weld the Hinge to the door(And unanchor the door and anchor the hinge if you havent)

Thats all :slightly_smiling_face:

ohh, I see, thanks for the help.

1 Like

and thanks for the help also xd

and also, the door spasms out, did I perhaps do something wrong?