Try changing
local hinge = door.Parent.hinge
to
local hinge = door:WaitForChild("hinge")
Then your hinge is in a different place or does not exist. Maybe post a screenshot of how you set up your door model?
Its just a part that look like this
and here is the information that you requested
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:
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")
But now it gives me this error
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:
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.
I’ll keep that in mind Thanks!
It gives me this error now
Thanks! I’ll be sure to check it out
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)
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
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