Menu
CoddyTech

The Button Door

Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 21 of 25.

The red button has a ClickDetector like the lamp. Setting Position moves a part instantly. To make it slide, use TweenService: you describe where the part should end up and how long the trip takes, and Roblox animates it.

local TweenService = game:GetService("TweenService")
local info = TweenInfo.new(2)
local goal = { Transparency = 1 }
local fade = TweenService:Create(workspace.Ghost, info, goal)
fade:Play()

TweenInfo.new(2) means 2 seconds. The goal is a table of property names and the values to end on. Create makes the tween, and nothing moves until you call Play. A tween can change numbers, Vector3 values like Position and Size, and Color3 colors.

challenge icon

Challenge

Medium

Slide the door 10 studs up when the red button is clicked.

  1. Make the tween: TweenService:Create(door, info, goal), with the info and goal that are ready.
  2. Connect to button.ClickDetector.MouseClick and play the tween inside, so the door waits for the click.

Press Play, walk up to the red button and click it: the door slides up over 1 second and you can walk through. Then Check.

Try it yourself

local TweenService = game:GetService("TweenService")
local door = script.Parent
local button = workspace.Button

local info = TweenInfo.new(1)
local goal = { Position = door.Position + Vector3.new(0, 10, 0) }

-- Make a tween of the door with info and goal

-- Play it when the button's ClickDetector is clicked

All lessons in Roblox Game Scripting

Practice on your own: Online Lua compiler