First steps, lesson 3
Variables
Goal: Store a value under a name and change it.
about 5 min4 practice exercises
A variable is a name for a value, so you can use it and change it later. Create one with local:
local coins = 3
print(coins)
coins = coins + 2
print(coins)
Line 1 creates coins and stores 3 in it. Line 4 reads the current value (3), adds 2, and stores the result back. The second print shows 5.
Two things to notice:
localis only used the first time, when you create the variable. After that you assign with=alone.print(coins)has no quotes, so it prints the value.print("coins")would print the word coins.
Pick names that say what the value is: coins, playerName, gateOpen. Names cannot start with a number or contain spaces.
Try it in Studio
Optional, and the best way to make it stick.
Make a variable for your own name and one for your coins, and print both.
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.