I'm making a nightstand that has a drawer that opens when it is clicked. I'm using CFrames to do it. The way I am currently doing this is by taking the position when the drawer is closed and then putting that into the script. Then moving the drawer to the position I want it to be at when closed and Cframing that.
Here is the code:
script.Parent.DrawerOpen.Value = false script.Parent.ClickDetector.MouseClick:connect(function(OpenDrawer) if script.Parent.DrawerOpen.Value == false then script.Parent.CFrame = CFrame.new(14, 1.595, 4.59) script.Parent.DrawerOpen.Value = true else if script.Parent.DrawerOpen.Value == true then script.Parent.CFrame = CFrame.new(14, 1.595, 2.99) script.Parent.DrawerOpen.Value = false end end end)
How can I make this do the same thing no matter where the model is at?
Thanks
SOLVED
script.Parent.DrawerOpen.Value = false script.Parent.ClickDetector.MouseClick:connect(function(OpenDrawer) if script.Parent.DrawerOpen.Value == false then script.Parent.CFrame = CFrame.new(script.Parent.Position + (script.Parent.CFrame.lookVector * -1.8)) script.Parent.DrawerOpen.Value = true else if script.Parent.DrawerOpen.Value == true then script.Parent.CFrame = CFrame.new(script.Parent.Position + (script.Parent.CFrame.lookVector * 1.8)) script.Parent.DrawerOpen.Value = false end end end)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(1,0,0) then script.Parent.CFrame = script.Parent.CFrame * CFrame.new(-1,0,0)
or
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,1) then script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,0,-1)
Depending on how you have your brick set up.