Project 580: Minecraft in Roblox - Part Three

7. Change 'Amount' Whenever the Player Places a Block

Change the existing code inside your block tool to decrease the value of amount whenever you place a block, and only allow the player to place a block if 'Amount' is greater than 0. 
Starting point file for this challenge

Your goal

Steps

1. Open your tool script

Open the script inside your block tool.

2. Add an 'amount' variable

At the beginning of your code, create a new local variable called 'amount' and set it equal to Tool.Amount.
local amount = Tool.Amount

3. Make a new line at the end of your 'makeBlock' function

Find the last line of your 'makeBlock' functions and add a new line after it.

4. Subtract 1 from 'Amount' when a block is placed

At the end of you 'makeBlock' function, make a new line the sets 'amount.Value' equal to 'amount.Value - 1'.
amount.Value = amount.Value - 1

5. Make a new line after the line that checks the player's distance in 'onClick'

Go into the 'onClick' function and find the line that checks if 'distance' is less than 'PlaceDistance'. Make a new line after it.

6. Check if 'amount.Value' is less than 1

Use and 'if-then' statement to check if 'amount.Value' is less than 1.

Don't forget to hit the 'return/enter' key to get an 'end' statement.
if amount.Value < 1 then end

7. Return if amount is less than 1

Use the word 'return' to exit the function if the player does not have any blocks left.
return