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)
endA 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
endA part that is see-through can still be solid: CanCollide = false is what lets players fall through.
Challenge
EasyMake the four bridge steps vanish and come back, forever.
- Wrap the
task.wait(2)and the loop below it inwhile true do ... end. - Inside it, after that loop, add another
task.wait(2)and a second loop that setsTransparencyto0andCanCollidetotrue.
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
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Roblox Game Scripting
2Loops and Functions
Row of PillarsStaircase BuilderTower BuilderCoin FactoryBlinking LightVanishing Bridge5Your First Game
Your First ObbyPractice on your own: Online Lua compiler