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

Why are my cframes messed up?[closed]

Asked by
AZDev 590 Moderation Voter
8 years ago

I have tried changing these values up, down, making them the same as each other. Nothing has seemed to work. I am making a door that opens when clicked. It opens just fine but each time I close it, it moves just slightly left and forward. Again I have tried the CFrame Values exactly the same going up the least possible increment going down the least possible increment. Still the same result. This is the code I wrote.

local door = false
local NoGlitchy = false --debounce
script.Parent.ClickDetector.MouseClick:connect(function()
    if NoGlitchy == false then 
        NoGlitchy = true
    if door == false then   
        for i = 1,16 do
            wait()
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,-.18,0.009) * CFrame.fromEulerAnglesXYZ(-0.098,0,0)  
        end
        door = true
        wait(0.3)
        NoGlitchy = false
    elseif door == true then
        for i = 1,16 do
            wait()
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,.178,0.007) * CFrame.fromEulerAnglesXYZ(0.098,0,0)   
        end
        door = false
        wait(0.3)
        NoGlitchy = false   
    end
    end
end)

If anyone could help I would be very happy.

1 answer

Log in to vote
-1
Answered by
AZDev 590 Moderation Voter
8 years ago

I found a rather simple solution to my problem.

local cframe = script.Parent.CFrame -- I simply needed to add this
local door = false
local NoGlitchy = false --debounce
script.Parent.ClickDetector.MouseClick:connect(function()
    if NoGlitchy == false then 
        NoGlitchy = true
    if door == false then   
        for i = 1,16 do
            wait()
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,-.18,0.009) * CFrame.fromEulerAnglesXYZ(-0.098,0,0)  
        end
        door = true
        wait(0.3)
        NoGlitchy = false
    elseif door == true then
        for i = 1,16 do
            wait()
            script.Parent.CFrame = script.Parent.CFrame * CFrame.new(0,.179,0.007) * CFrame.fromEulerAnglesXYZ(0.098,0,0)   
        end
        script.Parent.CFrame = cframe -- and this
        door = false
        wait(0.3)
        NoGlitchy = false   
    end
    end
end)

Now it works perfectly.

Ad

Answer this question