Menu
CoddyTech

Vanishing Bridge

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

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

Make the four bridge steps vanish and come back, forever.

  1. Wrap the task.wait(2) and the loop below it in while true do ... end.
  2. Inside it, after that loop, add another task.wait(2) and a second loop that sets Transparency to 0 and CanCollide to true.

Press Play: the steps fade out every 4 seconds and come back 2 seconds later. 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