How To Make an Elevator

From Goodblox Wiki
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
This is an Advanced, Building & Lua related tutorial.

Minimal requirements

To make an elevator (or a shifting brick that rises up and down at your command), you will need the following(minimally):

  • A flat brick on which you stand
  • In this flat brick, insert an object "BodyPosition".



  • One brick button on the elevator per floor (just like a real elevator -- you push "12" to go to the "twelfth" floor.) Weld these individual buttons to the floor. Do not anchor these buttons, or the elevator won't move.
  • One invisible, transparent, anchored, and Non-CanCollide brick per floor. These are 'marker' bricks. You will use the Position of these bricks to give the elevator reference as to where the floors are. Nobody "sees" them -- but the program uses them to know where the floors are.
  • Change the "BodyGyro" so that the X,Y,and Z values are the same in the flat brick.


BodyGyro makes your flat brick stay flat while your brick goes up and down, and is necessary for the proper functioning of an elevator.

  • Change the BodyPosition's position of the flat brick to the elevator's ground floor's marker Position brick. If you set it to a different position, your elevator will start the game in a different place. You want the elevator to start on the ground floor.

Script

The script in Button1 can look like this, for example:

Debounce = false

local b = script.Parent -- Button to ground floor
local p1 = script.Parent.Parent.Part1 -- the plate upon which you stand
local pos1 = script.Parent.Parent.pos1 -- position of ground floor
local pos2 = script.Parent.Parent.pos2 -- position of 2nd floor
local pos3 = script.Parent.Parent.pos3 -- position of 3rd floor, etc.


function onTouched(hit) 
	if (hit.Parent:FindFirstChild("Humanoid") ~= nil) then -- if it's a human
	if (Debounce == false) then 
	Debounce = true
	b.BrickColor = BrickColor.new(24)  -- change color to yellow
	p1.BodyPosition.position = pos1.Position -- go to ground floor
	p1.Anchored = false
	wait(5)
	b.BrickColor = BrickColor.new(1) -- change color to white
	Debounce = false
	end
	end
end

script.Parent.Touched:connect(onTouched) 

Optional

Recall buttons

So far we have a basic flat brick that can go up and down on command. What happens if you jump off your elevator platform on the third floor and now you want to get your elevator back down to the ground level?

  • Copy the button that is already on the elevator (as well as the script for it) which corresponds to the ground floor, and paste it into your elevator model.
  • Make sure the script is still a child of the newly created button.
  • Move this button onto the ground so that a person can "step" onto it, just as one would with the other buttons.
  • Change the size and color as you wish.
  • This button will recall the elevator to the ground when you step on it.