Keep ElseIf in Scope
An if statement can have many elseif
conditions, but they all must be coded between the first line of the if/then statement and the if/then statement’s end
.
- Test for the silver and bronze medals.


Troubleshooting Tips »
- Each
elseif
should have athen
after it’s condition. Example:elseif timePassed > 10 then
. - In
partTouched()
, make sure the second condition of the if statement uses==
, like inraceActive == true
. - Check that each
elseif
is in scope. Eachelseif
condition must be between the first line of the if/then statement and it’s lastend
.
Check using Else
If the player didn’t earn any of the medals, you should encourage them to try again. In this case, you can use an else
statement, which runs if no other conditions were true, to show them a message.
- Below the last
elseif
and aboveend
, start a new line and typeelse
. Do not addthen
. Beneathelse
, use a print statement to prompt them to try again.
- Playtest to see the
"Try again!"
message.

Troubleshooting Tips »
- Check that your else statement does not have a condition, like
timePassed <= 20
or athen
after it. - An else statement should always be the last check in an if statement. Check that the else statement does not have any other conditions, like
if
,elseif
, orelse
under it and theend
of that original if statement.
Optional Challenges »
Try a challenge to expand on the script.
- Add code so that when players finished, they can repeat the race by touching the start line.
- Design a way to display time during a race. You can either display the time on a part using a Surface GUI, like in the Creating a Timed Bridge tutorial, or check out the Intro to GUIs article to display the
timePassed
variable in a TextLabel. - Modify the script to use a table (see Creating and Using Tables) to keep track of all players when they join a game. Instead of using the
raceActive
boolean, give each player a boolean value instead to track whether or not they’ve finished the race.