Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

1 comment

0

TechSquad your answer doesn't work, and you cannot use "then" that way.

This discussion is preserved as it was. New answers, comments, and votes are closed.