Project 580: Minecraft in Roblox - Part Three

3. Keep Track of When the Player Clicks with the Pickaxe

Inside your Pickaxe script, create two new functions called 'onMouseDown' and 'onMouseUp' that change a new variable 'leftButtonDown' to true and false respectively. 
Starting point file for this challenge

Steps

1. Create the 'onMouseUp' function BEFORE the 'onEquipped' function

In your pickaxe script, make space above your 'onEquipped' function in your code. In that space, write the new function 'onMouseUp' which does not take any parameters. 

Don't forget to hit the 'return/enter' key to get an 'end' statement.
function onMouseDown() end

2. Set 'LeftButtonDown' to false

Set a variable called 'LeftButtonDown' equal to false. 
LeftButtonDown = false

3. Create the 'onMouseDown' function BEFORE the 'onMouseUp' function

Make space above your 'onMouseUp' function in your code. In that space, write the new function 'onMouseDown' which does not take any parameters. 

Don't forget to hit the 'return/enter' key to get an 'end' statement.
function onMouseDown() end

4. Set 'LeftButtonDown' to true

Set the 'LeftButtonDown' variable equal to true.
LeftButtonDown = true

5. Call the 'onClick' function

Call the 'onClick' function.
onClick()

6. Find the line that activates 'onClick' in your 'onEquipped' function

In your 'onEquipped' function, find this line of code:

myMouse.Button1Down:Connect(onClick)

which connects your 'onClick' function to the 'Button1Down' event.

7. Replace 'onClick' with 'onMouseDown'

On that line, inside the parentheses delete 'onClick' and replace it with 'onMouseDown'.
myMouse.Button1Down:Connect(onMouseDown)

8. Connect the 'Button1Up' event on 'myMouse' to the 'onMouseUp' function

Listen for a 'Button1Up' event on 'myMouse'. Connect it to your  'onMouseUp' function.
myMouse.Button1Up:Connect(onMouseUp)