In short
Make the car an unanchored part and move it with an AlignPosition (OneAttachment mode, MaxVelocity as the speed) and an AlignOrientation to keep it level. Mark each floor with an invisible stop part. Give every button a Floor number attribute and a ClickDetector. One Script inside the elevator Model queues the floors and sets the AlignPosition target to each stop in turn.
- An anchored part moved by TweenService has no velocity in the physics engine, so players on it are not carried smoothly. A physics-driven car is.
- Weld walls and inside buttons to the car with WeldConstraints so they move with it.
- Give the server network ownership of the car so it does not stutter when a player steps in.
Get the script
Elevator script with floor buttons
A Script inside an elevator Model that moves a physics-driven car between floor stops, queues button presses from inside and outside, and carries players.
-- Script inside the Elevator Model, named ElevatorScript.
-- Moves the Car between the parts in Stops when a button with a Floor attribute is clicked.
local SPEED = 10 -- studs per second
local DOOR_WAIT = 3 -- seconds to wait at each floor
local DEPART_DELAY = 1 -- seconds between closing the doors and moving
local LIT_COLOR = Color3.fromRGB(255, 200, 60)
local elevator = script.Parent :: Model
local car = elevator:WaitForChild("Car") :: BasePart
local stopsFolder = elevator:WaitForChild("Stops")
-- Floor number to the point the car's centre goes to
local stops: { [number]: Vector3 } = {}
for _, stop in stopsFolder:GetChildren() do
local floor = tonumber(stop.Name)
if floor and stop:IsA("BasePart") then
stops[floor] = stop.Position
end
end
-- Weld everything inside the car (walls, inside buttons) so it moves with it
for _, part in car:GetDescendants() do
if part:IsA("BasePart") then
part.Anchored = false
part.Massless = true
local weld = Instance.new("WeldConstraint")
weld.Part0 = car
weld.Part1 = part
weld.Parent = part
end
end
-- The car is moved by physics, so players standing on it are carried
car.Anchored = false
local attachment = Instance.new("Attachment")
attachment.Parent = car
local mover = Instance.new("AlignPosition")
mover.Mode = Enum.PositionAlignmentMode.OneAttachment
mover.Attachment0 = attachment
mover.Position = car.Position
mover.MaxVelocity = SPEED
mover.MaxForce = math.huge
mover.Responsiveness = 200
mover.Parent = car
local holder = Instance.new("AlignOrientation")
holder.Mode = Enum.OrientationAlignmentMode.OneAttachment
holder.Attachment0 = attachment
holder.CFrame = car.CFrame.Rotation
holder.MaxTorque = math.huge
holder.Responsiveness = 200
holder.Parent = car
-- The server simulates the car, so it does not jump when a player steps in
car:SetNetworkOwner(nil)
-- Find the floor the car starts at: the closest stop
local currentFloor = 1
local closest = math.huge
for floor, position in stops do
local distance = (position - car.Position).Magnitude
if distance < closest then
closest = distance
currentFloor = floor
end
end
elevator:SetAttribute("CurrentFloor", currentFloor)
-- Buttons: every part in the Model with a number attribute "Floor"
local buttons: { BasePart } = {}
local normalColors: { [BasePart]: Color3 } = {}
local normalMaterials: { [BasePart]: Enum.Material } = {}
local function lightButtons(floor: number, on: boolean)
for _, button in buttons do
if button:GetAttribute("Floor") == floor then
button.Color = if on then LIT_COLOR else normalColors[button]
button.Material = if on then Enum.Material.Neon else normalMaterials[button]
end
end
end
local queue: { number } = {}
local running = false
local function moveTo(floor: number)
local stop = stops[floor]
if not stop then
return
end
-- CurrentFloor 0 means "moving": doors close, then the car leaves
elevator:SetAttribute("CurrentFloor", 0)
task.wait(DEPART_DELAY)
-- Keep the car's own X and Z, so a stop placed slightly off-centre cannot pull it sideways
local target = Vector3.new(car.Position.X, stop.Y, car.Position.Z)
mover.Position = target
local started = os.clock()
local timeout = (target - car.Position).Magnitude / SPEED + 5
while (car.Position - target).Magnitude > 0.2 and os.clock() - started < timeout do
task.wait(0.1)
end
currentFloor = floor
elevator:SetAttribute("CurrentFloor", floor)
end
local function run()
running = true
while #queue > 0 do
local floor = table.remove(queue, 1) :: number
moveTo(floor)
lightButtons(floor, false)
task.wait(DOOR_WAIT)
end
running = false
end
local function request(floor: number)
if not stops[floor] or table.find(queue, floor) then
return
end
if floor == currentFloor and not running then
return
end
table.insert(queue, floor)
lightButtons(floor, true)
if not running then
task.spawn(run)
end
end
for _, part in elevator:GetDescendants() do
local floor = part:GetAttribute("Floor")
if part:IsA("BasePart") and type(floor) == "number" then
table.insert(buttons, part)
normalColors[part] = part.Color
normalMaterials[part] = part.Material
local detector = part:FindFirstChildOfClass("ClickDetector") or Instance.new("ClickDetector")
detector.MaxActivationDistance = 16
detector.Parent = part
detector.MouseClick:Connect(function(_player: Player)
request(floor)
end)
end
end
if next(stops) == nil then
warn("ElevatorScript: no stop parts named 1, 2, 3... in the Stops folder")
end
RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts
Where to put it
Workspace
Elevator Model
ElevatorScript Script new
Car Part (unanchored)
Wall Part
Button1 Part (attribute Floor = 1)
Stops Folder
1 Part (anchored, invisible)
2 Part
3 Part
CallButton2 Part (attribute Floor = 2)
Settings you can change
SPEEDIn the script- How fast the car moves, in studs per second. Above about 30, players can lose their footing. Default:
10. DOOR_WAITIn the script- Seconds the car waits at a floor before it moves on to the next one in the queue. Default:
3. FloorAttribute- A number on each button part: the floor it calls. Name the stop parts with the same numbers. Default: none.
The car must be unanchored and the stop parts anchored. Place each stop where the car should sit at that floor (Step 1).
Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.
Prompt for RoCode
Build an elevator in my game: a Model with an unanchored Car part moved by AlignPosition at 10 studs per second and kept level by AlignOrientation, anchored invisible stop parts named 1, 2 and 3 for the floors, buttons with a Floor attribute and a ClickDetector inside the car and on each floor, a queue of requested floors, lit buttons and a 3 second wait at each floor, with walls welded to the car.
On this page
How the elevator works
The car is a normal part that is not anchored, so physics can move it. An AlignPosition pulls it towards a target point, never faster than its MaxVelocity. Change the target to another floor and the car glides there at a steady speed. Because it really moves, with a velocity, a character standing on it moves with it, the same way you ride a bus.
| Method | Carries players? | Notes |
|---|---|---|
| Anchored car, TweenService on CFrame | Badly | The easiest to write. The car has no velocity, so players jitter on the way up and can fall behind on the way down. |
| Unanchored car, AlignPosition (this guide) | Yes | Physics moves it at a set speed to any point. Set up fully in code. |
| Unanchored car, PrismaticConstraint as a Servo | Yes | Slides along one axis to a TargetPosition at Speed, with ServoMaxForce as its strength. Set up with two attachments in Studio. |
Floors are marked with stop parts: invisible anchored parts placed where the car should be at each floor. You move a stop to fix a floor height, and the code never needs a number changed. Buttons are any parts with a Floor attribute; the script gives each one a ClickDetector.
Step 1: Build the elevator
- Build a shaft: four tall anchored wall parts with a gap on each floor for players to walk in. Leave at least half a stud between the shaft walls and where the car will be, so the car never rubs.
- Insert a Model in Workspace and name it
Elevator. (Select a part, press Ctrl+G to group it, then rename the Model.) - Add a Part to the Model named
Car: the floor of the elevator, for example 8 by 1 by 8 studs. Place it at the bottom floor. Untick Anchored. - Optional: add walls, a ceiling and buttons for inside the car as parts inside the Car part. The script welds them to the car.
- Add a Folder to the Model named
Stops. - Duplicate the Car (Ctrl+D), move the copy up to where the car should stop on floor 2, and drag it into Stops. Rename it
2. Do the same for every floor, including1where the car starts. - On every stop part: tick Anchored, set Transparency to 1, and untick CanCollide, CanTouch and CanQuery, so players never bump into them. Delete any walls that were copied inside them.
Buttons
- Make a small part for each button. Inside the car, put them inside the Car part. On each floor, put a call button anywhere inside the Elevator Model, anchored, next to the doorway.
- Select a button, scroll to Attributes in the Properties window, click +, name it
Floor, pick number and type the floor it calls, such as 2. - To label them, add a SurfaceGui with a TextLabel to each button, or a Decal with a number.
Workspace
Elevator Model
ElevatorScript Script new
Car Part (unanchored)
Wall Part
Button1 Part (attribute Floor = 1)
Button2 Part (attribute Floor = 2)
Button3 Part (attribute Floor = 3)
Stops Folder
1 Part
2 Part
3 Part
CallButton1 Part (attribute Floor = 1)
CallButton2 Part (attribute Floor = 2)
CallButton3 Part (attribute Floor = 3)
Step 2: The elevator script
Hover over the Elevator Model, click +, insert a Script named ElevatorScript and paste the code below.
-- Script inside the Elevator Model, named ElevatorScript.
-- Moves the Car between the parts in Stops when a button with a Floor attribute is clicked.
local SPEED = 10 -- studs per second
local DOOR_WAIT = 3 -- seconds to wait at each floor
local DEPART_DELAY = 1 -- seconds between closing the doors and moving
local LIT_COLOR = Color3.fromRGB(255, 200, 60)
local elevator = script.Parent :: Model
local car = elevator:WaitForChild("Car") :: BasePart
local stopsFolder = elevator:WaitForChild("Stops")
-- Floor number to the point the car's centre goes to
local stops: { [number]: Vector3 } = {}
for _, stop in stopsFolder:GetChildren() do
local floor = tonumber(stop.Name)
if floor and stop:IsA("BasePart") then
stops[floor] = stop.Position
end
end
-- Weld everything inside the car (walls, inside buttons) so it moves with it
for _, part in car:GetDescendants() do
if part:IsA("BasePart") then
part.Anchored = false
part.Massless = true
local weld = Instance.new("WeldConstraint")
weld.Part0 = car
weld.Part1 = part
weld.Parent = part
end
end
-- The car is moved by physics, so players standing on it are carried
car.Anchored = false
local attachment = Instance.new("Attachment")
attachment.Parent = car
local mover = Instance.new("AlignPosition")
mover.Mode = Enum.PositionAlignmentMode.OneAttachment
mover.Attachment0 = attachment
mover.Position = car.Position
mover.MaxVelocity = SPEED
mover.MaxForce = math.huge
mover.Responsiveness = 200
mover.Parent = car
local holder = Instance.new("AlignOrientation")
holder.Mode = Enum.OrientationAlignmentMode.OneAttachment
holder.Attachment0 = attachment
holder.CFrame = car.CFrame.Rotation
holder.MaxTorque = math.huge
holder.Responsiveness = 200
holder.Parent = car
-- The server simulates the car, so it does not jump when a player steps in
car:SetNetworkOwner(nil)
-- Find the floor the car starts at: the closest stop
local currentFloor = 1
local closest = math.huge
for floor, position in stops do
local distance = (position - car.Position).Magnitude
if distance < closest then
closest = distance
currentFloor = floor
end
end
elevator:SetAttribute("CurrentFloor", currentFloor)
-- Buttons: every part in the Model with a number attribute "Floor"
local buttons: { BasePart } = {}
local normalColors: { [BasePart]: Color3 } = {}
local normalMaterials: { [BasePart]: Enum.Material } = {}
local function lightButtons(floor: number, on: boolean)
for _, button in buttons do
if button:GetAttribute("Floor") == floor then
button.Color = if on then LIT_COLOR else normalColors[button]
button.Material = if on then Enum.Material.Neon else normalMaterials[button]
end
end
end
local queue: { number } = {}
local running = false
local function moveTo(floor: number)
local stop = stops[floor]
if not stop then
return
end
-- CurrentFloor 0 means "moving": doors close, then the car leaves
elevator:SetAttribute("CurrentFloor", 0)
task.wait(DEPART_DELAY)
-- Keep the car's own X and Z, so a stop placed slightly off-centre cannot pull it sideways
local target = Vector3.new(car.Position.X, stop.Y, car.Position.Z)
mover.Position = target
local started = os.clock()
local timeout = (target - car.Position).Magnitude / SPEED + 5
while (car.Position - target).Magnitude > 0.2 and os.clock() - started < timeout do
task.wait(0.1)
end
currentFloor = floor
elevator:SetAttribute("CurrentFloor", floor)
end
local function run()
running = true
while #queue > 0 do
local floor = table.remove(queue, 1) :: number
moveTo(floor)
lightButtons(floor, false)
task.wait(DOOR_WAIT)
end
running = false
end
local function request(floor: number)
if not stops[floor] or table.find(queue, floor) then
return
end
if floor == currentFloor and not running then
return
end
table.insert(queue, floor)
lightButtons(floor, true)
if not running then
task.spawn(run)
end
end
for _, part in elevator:GetDescendants() do
local floor = part:GetAttribute("Floor")
if part:IsA("BasePart") and type(floor) == "number" then
table.insert(buttons, part)
normalColors[part] = part.Color
normalMaterials[part] = part.Material
local detector = part:FindFirstChildOfClass("ClickDetector") or Instance.new("ClickDetector")
detector.MaxActivationDistance = 16
detector.Parent = part
detector.MouseClick:Connect(function(_player: Player)
request(floor)
end)
end
end
if next(stops) == nil then
warn("ElevatorScript: no stop parts named 1, 2, 3... in the Stops folder")
end
How the script works
- Stops: every part in the Stops folder named with a number becomes a floor. Its position is where the car's centre goes.
- Welding: parts inside the Car are unanchored, made massless and welded with WeldConstraints, so walls and inside buttons ride along without slowing the car.
- AlignPosition and AlignOrientation: pull the car to
mover.Positionat up to SPEED and keep it from tilting when players stand on one side.MaxForce = math.hugemeans a car full of players still moves at full speed. - The queue: each press adds a floor once. The car serves floors in the order they were pressed and waits DOOR_WAIT seconds at each. Lit buttons turn back off when the car arrives.
- The timeout in
moveTo: if something blocks the car, it gives up after the trip time plus 5 seconds and carries on with the queue instead of freezing.
Step 3: Add sliding doors (optional)
Doors stop players walking into an empty shaft. The simplest version is a door part on each floor that slides open while the car is at that floor. It is anchored, so TweenService is fine here: nobody rides a door. The ElevatorScript already writes CurrentFloor on the Model, so the doors only need to watch that attribute.
- On each floor, add an anchored part that fills the shaft doorway and name it
Door. Give it a number attributeDoorFloorwith its floor number. (NotFloor: the ElevatorScript would treat it as a button.) - Put all the doors in a Folder named
Doorsinside the Elevator Model. - Add a second Script to the Elevator Model named
ElevatorDoorswith the code below.
-- Script inside the Elevator Model, named ElevatorDoors.
-- Slides open the door whose DoorFloor matches the car's CurrentFloor, closes the others.
local TweenService = game:GetService("TweenService")
local OPEN_OFFSET = Vector3.new(0, 0, 6) -- how far a door slides, in the door's own space
local SLIDE_SECONDS = 0.6
local elevator = script.Parent :: Model
local doorsFolder = elevator:WaitForChild("Doors")
local closedCFrames: { [BasePart]: CFrame } = {}
for _, door in doorsFolder:GetChildren() do
if door:IsA("BasePart") then
door.Anchored = true
closedCFrames[door] = door.CFrame
end
end
local tweenInfo = TweenInfo.new(SLIDE_SECONDS, Enum.EasingStyle.Quad)
local function update()
local floor = elevator:GetAttribute("CurrentFloor")
for door, closed in closedCFrames do
local open = door:GetAttribute("DoorFloor") == floor
local goal = if open then closed * CFrame.new(OPEN_OFFSET) else closed
TweenService:Create(door, tweenInfo, { CFrame = goal }):Play()
end
end
elevator:GetAttributeChangedSignal("CurrentFloor"):Connect(update)
update()
The ElevatorScript sets CurrentFloor to 0 just before the car leaves and waits DEPART_DELAY (1 second), so every door closes first and nobody walks into an empty shaft. When the car arrives, only that floor's door opens. OPEN_OFFSET slides the door along its own Z axis: if your door slides into the wall instead of along it, try Vector3.new(6, 0, 0).
For doors players open themselves, with swing or slide and keys, see the door script guide.
Step 4: Test it
- Press Play and open the Output window. A warning about stop parts means the Stops folder is empty or the parts are not named with numbers.
- Walk into the car and click the button for floor 2. It lights up, the car rises at 10 studs a second with you on it, and the light goes off when it stops.
- Click several floors quickly. The car visits them in the order you clicked.
- Stand outside on floor 3 and click the call button there. The car comes up to you.
- Jump while the car moves: you should land back on it, not fall through.
Common errors and fixes
Check the Output window first: a red line names the script and the line.
Clicking a button does nothing
Check the button has an attribute named exactly Floor of type number, that it is inside the Elevator Model, and that a stop part with that number exists. You must be within 16 studs, the MaxActivationDistance the script sets.
Players slide or jitter on the car
The car is anchored, or another script tweens it. It must be unanchored and moved only by the AlignPosition.
Infinite yield possible on WaitForChild("Car")
The car part must be named exactly Car and sit directly inside the Elevator Model. See Infinite yield possible.
The car stops a little above or below the floor
Move that floor's stop part. The car's centre goes exactly to the stop's centre, so line the stop up with where the car should be.
Network ownership API cannot be called on anchored parts
The Car was anchored when the script ran. The script unanchors it first, so this means another script anchored it again. See that error's page.
Build it with RoCode
If you would rather not build it by hand, RoCode can add an elevator to the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the parts and scripts in your Explorer.
Add an elevator to my apartment building that stops at all 4 floors, with buttons inside and a call button on each floor, sliding doors, and make sure players ride it smoothly.
- Can read your place first to find the building and measure the floor heights for the stops
- Writes the scripts with Create Script and is told to compile-check each one with Check Script
- Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time
After a build, RoCode can run its test robot, which plays your game in Studio and reports PASS or FAIL on what it chose to test, so ride the elevator yourself too. How RoCode connects to Studio.
Questions
How do I make an elevator in Roblox Studio?
Make an unanchored car part, move it with AlignPosition between invisible stop parts, and give buttons a Floor attribute and a ClickDetector. Step 2 has the full script.
Why do I fall through or slide on my TweenService elevator?
A tweened anchored part has no velocity in the physics engine, so it does not carry what stands on it. Move an unanchored car with a constraint instead.
Can I make an elevator with a PrismaticConstraint?
Yes. Put one attachment on an anchored base and one on the car, set the PrismaticConstraint's ActuatorType to Servo, and change its TargetPosition for each floor. Check which direction is positive in Studio first.
How do I make an elevator button with a ProximityPrompt?
Swap the ClickDetector for a ProximityPrompt in the button loop and connect Triggered instead of MouseClick. The ProximityPrompt guide shows the setup.
How fast should a Roblox elevator move?
About 8 to 15 studs a second feels right. Much faster and players can lose their footing when the car stops.
Sources and further reading
- Roblox Creator Docs: AlignPosition. OneAttachment mode, MaxVelocity and MaxForce
- Roblox Creator Docs: PrismaticConstraint. the sliding alternative and its Servo settings
- Roblox Creator Docs: ClickDetector. MouseClick and MaxActivationDistance
- Roblox Creator Docs: Network ownership. why the server keeps the car
How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.