Roblox Heist: Collecting Coins

Step 1
In this lesson we will be creating collectible coins which award the player points

We will also be learning to add a ScreenGUI to display the number of coins

Step 2
Create a new roblox project and delete the Baseplate
Step 3
Create a Cylinder which will represent our coin

Also create a Spawn Platform and a little area for the coin to sit upon


If you know how to do more advanced modeling, you can try to add a rim around the cylinder like I did, or you can design something besides just a coin.

Step 4
Rename the cylinder to "Coin" in the Workspace tab
Step 5
Add a Script component to the Coin, name it "Collectible"

Rename the Script to something like "Collectible"

Step 6
We'll start the script by creating a variable "player" representing the specific character object containing the script
Step 7
Create a function named "pickUpCoin()"

Just for now this function will simply print You got a coin! to the screen

Step 8
In order to call the pickUpCoin() function we need to connect it to a Roblox Event

Roblox Objects let you 'connect' functions to in-game Events


Since we want to call the pickUpCoin() function after the coin is touched, we'll connect it to the Touched event

Step 9
The player has many pieces!
Temp1557009849 Temp1557010392
Step 10
Remove the pieces that aren't physical
Temp1557010625 Temp1557010785
Step 11
Connect the Touched event of each part to our "pickUpCoin" function
Check Your Work
Step 12
Our message should now be output when we touch ANYTHING in our game

Open the Ouput using the view tab as shown below:

Step 13
Make sure we are touching a coin
Step 14
Add a Destroy() method to delete the coin after the player touches it

Note the in Lua we use : when calling object methods (actions)

Step 15
Next we are going to add a sparkle effect to the player after they pick up a coin

This sparkle is attached to the player's torso so that it follows them as it plays

Step 16
First press the play button so that you can see your player object in the workspace

Any changes we make right now are temporary and will disappear when you press "stop".

Step 17
Open the player and navigate down to find the UpperTorso, then add a Sparkles component

Click the (+) and add Sparkles:

Step 18
Change the sparkle color by selecting it in the workspace explorer and setting "Color" in the data tab
Step 19
Once you have the sparkles the way you like them, rename the object to "CoinSparkles"
Step 20
Copy the CoinSparkles Object

We are going to stop the program in the next step and all of these changes will be deleted

Step 21
Once you have copied the CoinSparkles object, then feel free to press Stop
Step 22
In the Explorer window, paste the CoinSparkles into "ReplicatedStorage"

This lets us make Clones of the CoinSparkles whenever the player touches a coin in-game

Step 23
Back in our pickUpCoin() function you can now find CoinSparkles in game.ReplicatedStorage

Now we'll be able to use this to create sparkles when the coin is collected

Step 24
We can use the Clone method to create a clone of the CoinSparkles object
Step 25
This won't be enough to see the sparkles though

Objects have to be parented to the Workspace in order to appear in the game world

Step 26
Store the Coin clone in a reference variable which we can use to set the coin's parent

This lets us refer to the coin clone as coinSparkles in our Script

Step 27
We can set the Parent of the coin sparkles to be the player's Upper Torso

Now we can set the Coin's parent to the player's Upper Torso

Check Your Work
Step 28
Now the coin can be picked up by players and the sparkles will attach to the player's torso
Step 29
Create a Script named "Disappear" on the CoinSparkles object
Step 30
This script waits 1 second before destroying the coin
Check Your Work
Step 31
Now when we collect a coin, the sparkles will only last a short time
Step 32
Next we'll make a GUI which displays the number of coins the player has collected
Step 33
Add a ScreenGui object to the StarterGui Folder

Every player in the game will begin with a GUI copied from this folder

Step 34
Now add a TextBox to the ScreenGUI

Rename it to something like PointText

Step 35
Drag the textbox on your screen to where you'd like the points to be displayed
Step 36
You can change the properties of the text by selecting it and going to the lower-right "Properties" window

I recommend you change TextSize, TextColor3, BackgroundColor3, and BackgroundTransparency

Temp1532029873 Temp1532029900
Step 37
Change the starting Text to 0
Step 38
When the game is played each player is given a copy of StarterGUI in their PlayerGUI folder

When the game is played you can see the "PointText" object we need to change is stored here


Game.Players[your name].PlayerGUI.ScreenGui.PointText

Step 39
So we'll go ahead an insert that long line of code right into our Coin's "Collectable" script

And then we'll increase PointText's "Text" value by 1

Check Your Work
Step 40
You should now be able to collect the coin and see your points increase by 1
Check Your Work
Step 41
Once you have it working you can copy and paste to add as many coins as you'd like
Step 42
In the next lesson we will be making an exploding trap
Roblox Heist: Collecting Coins 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