Menu
CoddyTech

Vanishing Bridge

Part of the Roblox Game Scripting section of Coddy's Lua journey. Lesson 10 of 24.

The blinking light changed one part. A bridge has many steps, and they all have to change together.

GetChildren() returns an object's direct children as a table, ready for a for loop. Functions that belong to an object, like GetChildren, are called with a colon:

for _, child in workspace.Bridge:GetChildren() do
	print(child.Name)
end

A folder can hold your Script too, and a Script has no Transparency. child:IsA("BasePart") is true for every kind of part and false for the Script. if condition then ... end runs the lines inside only when the condition is true:

if child:IsA("BasePart") then
	child.Transparency = 0.8
end

A part that is see-through can still be solid: CanCollide = false is what lets players fall through.

challenge icon

Challenge

Easy

The bridge has four steps over the void, and this script is in the bridge's folder. It makes the steps vanish once. Make the bridge cycle forever:

  • 2 seconds after the start the steps vanish: Transparency 0.8, CanCollide false
  • 2 seconds later they come back: Transparency 0, CanCollide true
  • this repeats every 4 seconds, forever

Press Play and time your run across, then Check.

Try it yourself

local bridge = script.Parent

-- This makes the steps vanish ONCE, after 2 seconds.
-- Make them come back 2 seconds later, and repeat forever.
task.wait(2)
for _, step in bridge:GetChildren() do
	if step:IsA("BasePart") then
		step.Transparency = 0.8
		step.CanCollide = false
	end
end
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Roblox Game Scripting

Practice on your own: Online Lua compiler