Hi all, I have made a door which works relatively well but if I rotate it the scrip doesn't work as intended. I would like to amend the script (below) so the hinge works even when not aligned with the X axis, I have tried but don't really know where to start (returning from a long break). Could anyone help me or point me in the right direction?
Thank you!
local door = script.Parent
local closed = true
local hinge = script.Parent.hinge
local hingePos = hinge.Position
local hingeOri = hinge.Orientation
local clicked = door.ClickDetector
local canClick = true
local angle = 120
local size = CFrame.new(((-5.015/2)+(-0.425/2)), 0, 0)
function open()
if canClick == true and closed == true
then canClick = false
for i = 1, angle do
door.CFrame = CFrame.new(hingePos) * CFrame.Angles(0, math.rad(-i), 0) * size
wait(0.005)
end
canClick = true
closed = false
end
wait(20)
if closed == false
then close()
end
end
function close()
if canClick == true and closed == false
then canClick = false
closed = true
for i = 1,angle do
door.CFrame = CFrame.new(hingePos) * CFrame.Angles(0, -math.rad(angle-i), 0) * size
wait(0.005)
end
canClick = true
end
end
clicked.MouseHoverEnter:connect(open)
clicked.MouseHoverEnter:connect(close)
