Roblox Heist: Police Chase

Step 1
First create a Timer in the same way you did your Points text box
Temp1532651008 Temp1532650969

Make it big and noticeable in the center of your screen

Step 2
Set the timer's "Visible" property to false

Untick the checkbox so the timer starts out invisible.

Step 3
Add a new Local Script to your player's Starter Scripts. This script with play the timer sequence

Because my timer is police themed, I named it PoliceChase.

You can name yours whatever you'd like.

Step 4
This script will store a "global function" named 'StartTimer'

_G. signifies that this is a global function


A global function can be called from any other script.

Step 5
For now this function will simply print a message

We're next going to learn how to call this global function from another script...

Step 6
In the next few steps we will be adding a script to the Rare Jewel which will call the global StartTimer() function

Start by adding a script named PickUpJewel to the Rare Jewel.

Step 7
First we'll have the script identify the jewel object

The script is a child of the jewel and thus script.parent refers to the jewel itself.

Step 8
Create a function named "onEquipped" and connect it to the "Equipped" Event

The Equipped Event is built-in to Roblox
onEquipped is a function we just now created

Step 9
Using _G call the global StartTimer() function

When the jewel is equipped, we call StartTimer().

Check Your Work
Step 10
Calling the global function in the pick-up script should activate it in the timer script

The _G stores these functions


You in fact see that the function is called when you pick up the gem

Step 11
We have one problem to fix though, the StartTimer() function is called *every time* the player takes out the jewel

We only want it to start the timer the first time it is equipped.

Step 12
We will add a boolean to check if the jewel has been pickedUp already

When the game starts, pickedUp is initialized as false.

Step 13
Here we say to only start the timer if the jewel hasn't been picked up yet

Note that we set pickedUp = true so that StartTimer won't be called again.

Check Your Work
Step 14
Verify that StartTimer is only called once no matter how many times you equip the jewel
Step 15
Now that that's taken care of, we're going to build this script together

The three phases of StartTimer():

  • Display some kind of "Escape before time runs out!" message
  • Create a while loop to count down
  • Kill the player if the timer hits 0
Step 16
First, our script need to reference the player

We can see on the right, that the player is the script's -> parent's -> parent.

Step 17
We also need to reference the timer GUI object

We initialize the timer once the StartTimer function is called because timer GUI objects are destroyed whenever the player dies, and that'd be a problem if we only initialized it to be the first timer at the start of the game.

Step 18
Now we can use the timer reference variable to tell our timer GUI to appear and display text
Check Your Work
Step 19
You should see your message display when you grab the jewel
Step 20
Next we will have the script wait 2 seconds before starting a countdown timer

timeRemaining starts at 100 and while it is greater than 0, we subtract 1 from timeRemaining:

Step 21
Then we can update timer's Text to display the timeRemaining
Check Your Work
Step 22
If we hit Run right now, the timer will instantly count down to 0

While loops run every loop in a single frame unless told to wait()

Step 23
In Lua, we can use wait() to make the while loop wait a single frame before repeating

You could also say wait(1) to count in seconds rather than frames

Step 24
After the while loop ends we'll have the timer announce the player has run out of time and set their health to 0

Brackets [ ] are an alternate way of using .

This code is the same as workspace.MVCCJamie since == "MVCCJamie"

Check Your Work
Step 25
Test that the player now dies if the timer runs out
Step 26
Create a second global function named StopTimer
Step 27
This function will make the timer invisible when it is called

Of course, the timer will still be ticking in the background...

Step 28
Add an if statement so that when the timer runs out, it only kills the player if it is visible

So when StopTimer() is called, the timer becomes invisible, which means it won't kill the player when it runs out.

Step 29
Create and "End" object which calls "StopTimer()" if a player touches it

I made an invisible block with some Sparkles to signify my "end" object



  • The script needs a reference to the Part
  • The script should Connect a function to the Part's Touched method
  • Use _G. to call a global function
  • Set your timeRemaining to start at a higher value
Check Your Work
Step 30
Your timer should now stop running when the player reaches the "End" of the course
Step 31

You've now reached the end of the course, and it's time for you to make this game your own.

Here are some ideas to get you started:

To my game I added:

  • a flashing red and blue police light to the player
  • made the timer count in minutes and seconds
  • made the timer flash red and blue
Step 32
Here i how I created the flashing Red and Blue light

I created a point light inside of ReplicatedStorage and attached a script named flash

Step 33
The flash script uses a back-and-forth (sine) tween to change the light color between red and blue

TweenInfo takes inputs in this order:

  • time
  • style (sine for back-and-forth)
  • direction
  • # of times to repeat (-1 for infinite)
  • reverse direction? (true/false)
Step 34
I used the same technique to change the timer background color
Step 35
That's it! What else can you think to add?

Some ideas:

  • enemies
  • different types of treasure
  • lava/water
  • bigger level
  • buttons that control other things
Roblox Heist: Police Chase Info


MVCode Clubs

Created By

Newprofile jamie


Roblox Heist Game

Access Level


For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.

Learn more about MVCode Teach