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

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

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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)
0
Thanks so much! Florian27 76 — 7y
Ad

Answer this question