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

How do I make a sliding door?

Asked by 10 years ago

I'm trying to make a door which, when a button is pressed, slides to the right. But it's sort of different to that. I want my door to be like this:

When a button is pressed, several rocks move to the right, uncovering a secret tunnel. Is it possible to do this? If so, help me out! :)

1 answer

Log in to vote
1
Answered by
jobro13 980 Moderation Voter
10 years ago

As thumb rule you can say that you can make everything. Some things are technically impossible and some things are possible but will overwhelm CPU resources.

That's absolutely not the case in this. Basically, you have rocks, which you could say are several doors which you are sliding to the right. This is very objective though as I don't really know what to "right" is, it depends on your viewpoint.

I would create it as this:

function drag(doors)
    for i = 1,30 do
        for i, rock in pairs(doors) do
            rock.CFrame = rock.CFrame * CFrame.new(0,0,0.2)
        end
        wait()
    end
    wait(5)
    for i = 1,30 do
        for i,rock in pairs(doors) do
            rock.CFrame = rock.CFrame * CFrame.new(0,0,-0.2)
        end
    end
end

local doors = {}
table.insert(doors, game.Workspace.Rock1)
table.insert(doors, game.Workspace.Rock2)
-- and so on
-- an event happens:
drag(doors)

You will notice however that the doors are sliding to the left, or in the wall, or from it. You need to either change the CFrames to one of the following:

CFrame.new(0,0,-0.2) and CFrame.new(0,0,0.2)

or

CFrame.new(0.2,0,0) and CFrame.new(-0.2,0,0)

or

CFrame.new(-0.2, 0, 0) and CFrame.new(0.2,0,0)

0
How do I make it so that when I click a button it moves? ClassiclySmart 10 — 10y
0
Call drag(doors) when the button is clicked, thus ClickDetector.MouseClick:connect(function() drag(doors) end) jobro13 980 — 10y
0
I tried making the doors and it didn't work, I put the doors I wanted in a group named 'Doors' and made changes to the script: table.insert(doors, game.Workspace.Doors.Rock1) ClassiclySmart 10 — 10y
0
try doors = game.Workspace.Doors:GetChildren() - remove every "table.insert" line. jobro13 980 — 10y
0
Still doesn't work. ClassiclySmart 10 — 10y
Ad

Answer this question