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

Why won't this door-opening button work?

Asked by 9 years ago

I've made two buttons in the Workspace, each with a script and a ClickDetector inside. One button opens two doors simultaneously, and the other closes them. The 'open' button works perfectly. Here's its code:

local dR = game.Workspace.DoorRight
local dL = game.Workspace.DoorLeft

function onClicked()
    if dL.CFrame == CFrame.new(2, 4.5, 8.2) and dR.CFrame == CFrame.new(-2, 4.5, 8.2) then
        for i = 1, 4.5, 0.1 do
            dR.CFrame = CFrame.new(dR.Position + Vector3.new(-0.1, 0, 0))
            dL.CFrame = CFrame.new(dL.Position + Vector3.new(0.1, 0, 0))
            wait()
        end
    end

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

The 'close' button doesn't work. Here's its code:

local dR = game.Workspace.DoorRight
local dL = game.Workspace.DoorLeft

function onClicked()
    if dL.CFrame == CFrame.new(5.5, 4.5, 8.2) and dR.CFrame == CFrame.new(-5.5, 4.5, 8.2) then
        for i = 1, 4.5, 0.1 do
            dR.CFrame = CFrame.new(dR.Position + Vector3.new(0.1, 0, 0))
            dL.CFrame = CFrame.new(dL.Position + Vector3.new(-0.1, 0, 0))
            wait()
        end
    end

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

All of the positions in each script are correct. The doors are each 4, 8, 0.4 in size. I don't know why the red button won't work. Can someone help?

Answer this question