Need help with tweening a door around a hinge

Try changing
local hinge = door.Parent.hinge
to
local hinge = door:WaitForChild("hinge")

1 Like

Now it says this

1 Like

Then your hinge is in a different place or does not exist. Maybe post a screenshot of how you set up your door model?

1 Like

Its just a part that look like this
a4
and here is the information that you requested
a3

The model in the tutorial requires at least 2 parts: The main part for how the door looks and the “Hinge” part that the door rotates around. You should make something like this instead:

Capture
Capture

Notice how I have a part called “Hinge”. You should reference the part underneath the model like so:

local door = script.Parent
local hinge = door:WaitForChild("Hinge")
1 Like

But now it gives me this error
a5

local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local self = script.Parent
local door = self:WaitForChild("Part")
local hinge = self:WaitForChild("Hinge")

local offset = hinge.CFrame:Inverse() * door.CFrame
local doorInfo = TweenInfo.new()
local doorOpen = TweenService:Create(door.Angle, doorInfo, {Value = 90}) 
local doorClose = TweenService:Create(door.Angle, doorInfo, {Value = 0})

RunService.Heartbeat:Connect(function(hit)
	door.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(door.Angle.Value), 0) * offset
end)

task.wait(3)
doorOpen:Play()
task.wait(3)
doorClose:Play()

This might help you out a lot:

1 Like

I just realized that the tutorial you’re following uses RunService to open its doors. You shouldn’t rely on that behavior. Instead, just use the TweenService and welds.

1 Like

I’ll keep that in mind Thanks!

It gives me this error now
a

1 Like

Thanks! I’ll be sure to check it out

1 Like

You don’t really need an Angle instance. You can do this instead. Note that this method requires the door to be welded to the hinge part. You can do this using a WeldConstraint or find a Weld plugin online.

local TweenService = game:GetService("TweenService")

local self = script.Parent
local hinge = self:WaitForChild("Hinge")

local angle = 90
local doorInfo = TweenInfo.new()
local doorOpen = TweenService:Create(hinge, doorInfo, {CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(angle), 0)}) 
local doorClose = TweenService:Create(hinge, doorInfo, {CFrame = hinge.CFrame})

task.wait(3)
doorOpen:Play()
task.wait(3)
doorClose:Play()

I recommend doing math.rad(-angle). It will rotate it better. (I’m not an expert at CFrames I might be wrong)

1 Like
local TweenService = game:GetService("TweenService")

local self = script.Parent
local hinge = self:WaitForChild("Hinge")

local angle = 90
local doorInfo = TweenInfo.new()
local doorOpen = TweenService:Create(hinge,doorInfo,{CFrame = hinge.CFrame * CFrame.Angles(0,math.rad(angle),0)})
local doorClose = TweenService:Create(hinge,doorInfo,{CFrame = hinge.CFrame})

task.wait(3)
doorOpen:Play()
task.wait(3)
doorClose:Play()

I have followed your step but it dint give me any errors this time but the door dint move at all
a1
a2

Make sure that the door part is unanchored and the Hinge is anchored.

The result is the same the door wont move at all

Here. Compare it with yours to see what you did wrong.

DoorHinge.rbxl (29.8 KB)

I used a normal Weld instead of a WeldConstraint because WeldConstraints aren’t the best.

Cant u just use a HingeConstraint? Those are better and more customisable

Yes you could. Here is an example:

HingeDoor.rbxl (34.7 KB)