UevKF8zjRV_WEtpJsXhr
We use cookies on this site to enhance your user experience

Keep the Bridge from Restarting

To keep the timer from constantly restarting, you’ll need to add another variable that will control whether or not startTimer() is allowed to be called again. This variable will use a new type of value called a boolean. Booleans are written the same way as other variables, but instead of using numbers or strings, they can only be set to true or false.

In this situation, the script will use a boolean to check if the timer is currently running before starting it.

  1. At the top of your script under your variables, create a variable named timerActive and set it to false since nobody has pressed the button yet.
  1. To makes sure startTimer() only starts when timerActive is false, add a second condition to the if statement in buttonPressed().
  1. To keep startTimer() from restarting before the timer runs out, set the boolean timerActive to true.
  1. Playtest the game and make sure the timer doesn’t restart anymore. While the timer doesn’t restart, it also can’t be used more than once. To make the button reusable, you’ll reset the boolean in the next section.
Troubleshooting Tips

Issue: Timer changes numbers without counting down:

  • Check that you’ve added a second condition in buttonPressed's if statement.
  • Make sure at the beginning of startTimer() that you set timerActive to true.

Reset the Timer

To finish the script, you’ll change the boolean and bridge properties back to what they were at the start of the game so the bridge can be used more than once.

  1. In the startTimer() function, after the for loop, set the bridge back to its original properties by changing the bridge’s transparency to 0.8 and CanCollide to false.
  1. Right now the display text stays at 0. To make it blank again, change the timerText to an empty string.
  1. Since you’re now done with the timer, set the timerActive boolean to false. This will also allow the timer to restart next time the button is touched.
  1. Playtest and check to make sure the bridge can be used multiple times.

Finished Project Sample

Project File

Download the finished project here.

Finished Script