I’m an absolute noob at CFrames and so far the only code I’ve done so far has been the combination of YouTube videos which didn’t quite explain CFrames very well to me with what I’m trying to accomplish.
Basically, I have a fridge and I’m trying to make the door and the handle of the door rotate at the same time so that I can create an opening animation with the door but it’s going horribly wrong but I don’t know how to fix it at all since I don’t understand CFrames much at all.
Here’s a video of what’s happening (not sure if I did it right or not, not showing up in preview):
The script that I’m using for that:
local Hinge = script.Parent.LeftHinge
local leftdebounce = false
local lefttoggle = false
script.Parent["Meshes/LeftDoor"].ClickDetector.MouseClick:Connect(function(Player)
if leftdebounce then return end
leftdebounce = true
if not lefttoggle then
for i = 270, 110, -1 do
spawn(function()
script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
end)
pcall(function()
script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
end)
wait()
end
leftdebounce = false
lefttoggle = true
else
for i = 110, 270 do
spawn(function()
script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
end)
pcall(function()
script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
end)
wait()
end
leftdebounce = false
lefttoggle = false
end
end)
script.Parent["Meshes/LeftDoorHandle"].ClickDetector.MouseClick:Connect(function(Player)
if leftdebounce then return end
leftdebounce = true
if not lefttoggle then
for i = 270, 110, -1 do
spawn(function()
script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
end)
pcall(function()
script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
end)
wait()
end
leftdebounce = false
lefttoggle = true
else
for i = 110, 270 do
spawn(function()
script.Parent["Meshes/LeftDoorHandle"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
end)
pcall(function()
script.Parent["Meshes/LeftDoor"].CFrame = CFrame.new(Hinge.Position) * CFrame.Angles(0, math.rad(i), 0) * CFrame.new(1.35, 0, 0)
end)
wait()
end
leftdebounce = false
lefttoggle = false
end
end)
-- The right door is the same thing but renamed "RightDoor" and "RightDoorHandle"
Just a small note: I used a spawn()
and a pcall()
right after on another because the door and the handle were separate meshes so I thought I’d call one in a thread to run by itself while yielding for the other to catch up but I don’t think that did anything.
The main issue here is that the left door rotates backwards and the right door’s handles rotates too little to match the door’s rotation (or maybe the handle is rotating backwards)
Any articles on CFrames or just help in general is much needed, these YouTube videos really didn’t explain much in the technical process.
Thanks in advance.