Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Can I get some help with some CFraming?[Closed]

Asked by
AZDev 590 Moderation Voter
9 years ago

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

2 answers

Log in to vote
0
Answered by
AZDev 590 Moderation Voter
9 years ago

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)


Ad
Log in to vote
-3
Answered by 9 years ago

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.

0
TechSquad your answer doesn't work, and you cannot use "then" that way. AZDev 590 — 9y

Answer this question