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

Making a part stay in it's position? || Rotations

So, every time I click the curtain, it keeps rotation (I don't know much about rotations). my code:

local s = script.Parent

local switch = true
s.ClickDetector.MouseClick:connect(function()
	if switch == true then
		switch = false
		s.Rotation = Vector3.new(0, 90, 0)
		s.Size = Vector3.new(15.216, 8.503, 0.2)
		s.CFrame = CFrame.new(10.1, 8.25, -54.408)
		
	elseif switch == false then
		switch = true
		s.Rotation = Vector3.new(0, 90, 0)
		s.Size = Vector3.new(2.416, 8.503, 0.2)
		s.CFrame = CFrame.new(10.1, 8.25, -54.408)
	end

end)

Thanks for the help :)

1 answer

✓ Accepted answer

If you want it to keep its rotation, you can subtract the position from the old CFrame, then add it back on, like this:

local s = script.Parent

local switch = true
s.ClickDetector.MouseClick:connect(function()
    if switch == true then
        switch = false
        s.Rotation = Vector3.new(0, 90, 0)
        s.Size = Vector3.new(15.216, 8.503, 0.2)
	local oldRotation = s.CFrame - s.Position
        s.CFrame = CFrame.new(10.1, 8.25, -54.408) * oldRotation

    elseif switch == false then
        switch = true
        s.Rotation = Vector3.new(0, 90, 0)
        s.Size = Vector3.new(2.416, 8.503, 0.2)
	local oldRotation = s.CFrame - s.Position
        s.CFrame = CFrame.new(10.1, 8.25, -54.408) * oldRotation
    end

end)

1 comment

0

Thanks so much!

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