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

How would I make an object move along its own axis?

Asked by 6 years ago

Say I have a door that opens when you touch it. The problem with my current script is it only works right if it isn't rotated in a different direction.

door = script.Parent.Parent
debounce = false
openTime = 2

script.Parent.Touched:connect(function(p)
    if p.Parent:FindFirstChild("Humanoid") and debounce == false then
        debounce = true
        for i = 1, 20 do
            wait(0.005)
            door.Left.CFrame = door.Left.CFrame + Vector3.new(0,0,0.1)
            door.Right.CFrame = door.Right.CFrame + Vector3.new(0,0,-0.1)
        end
        wait(openTime)
        for i = 1, 20 do
            wait(0.005)
            door.Left.CFrame = door.Left.CFrame + Vector3.new(0,0,-0.1)
            door.Right.CFrame = door.Right.CFrame + Vector3.new(0,0,0.1)
        end
        debounce = false
    end
end)

How do I make it work at any rotation?

Answer this question