Sign in
Home
Online Classes
Instructors
Tutorials
☰
Register
Sign in
Online Classes
Instructors
Tutorials
1. Open your file from part 2
2. Add a Toughness Value to the Blocks Being Placed
3. Keep Track of When the Player Clicks with the Pickaxe
4. Let the Pickaxe Break Blocks Based on Toughness
5. Create a Surface GUI and an IntValue to Your Block Tool
6. Update the GUI to Display 'Amount'
7. Change 'Amount' Whenever the Player Places a Block
8. Allow the Player to 'Pick Up' the Blocks They Break
9. Multiple Types of Blocks
Project 580: Minecraft in Roblox - Part Three
4. Let the Pickaxe Break Blocks Based on Toughness
Edit the pickaxe code to uses the 'toughness' value of each block to determine how long it takes to break each block.
Starting point file for this challenge
Your goal
Hint: show steps
Steps
1. Add a variable 'breakable' after 'myTarget' at the top of the script
Hint: show details
Add a new line at the top of your script after you make your 'myTarget' variable, and make a new local variable called 'breakable' and set it equal to 'false'.
local breakable = false
Hint: show image
Hint: show code
2. Find the line that destroys the block in your 'onClick' function
Hint: show details
In your 'onClick' function, find the line of code that uses the 'Destroy()' function on 'myTarget'.
Make a new line BEFORE that line.
Hint: show image
3. Find the toughness of the target block
Hint: show details
Use the 'FindFirstChild' function on 'myTarget' to get the toughness value of the target block.
myTarget:FindFirstChild("Toughness").Value
Hint: show image
Hint: show code
4. Store the toughness in 'breakTime'
Hint: show details
Create a new local variable called 'breakTime' and set it equal to the toughness value, using the code from the previous step.
local breakTime = myTarget:FindFirstChild("Toughness").Value
Hint: show image
Hint: show code
5. Set 'breakable' to true
Hint: show details
Set the 'breakable' variable equal to
true
.
breakable = true
Hint: show image
Hint: show code
6. Make a for-loop that starts at 1 and repeats 'breakTime' number of times
Hint: show details
Create a 'for-loop' that starts the variable 'timer' at 1 and repeats itself the number of times stored inside the 'breakTime' variable.
Don't forget to hit the 'return/enter' key to get an 'end' statement.
for timer=1, breakTime do end
Hint: show image
Hint: show code
7. Check if 'LeftButtonDown' is false
Hint: show details
Use an 'if-then' statement to check if 'LeftButtonDown' is false.
Don't forget to hit the 'return/enter' key to get an 'end' statement.
if LeftButtonDown == false then end
Hint: show image
Hint: show code
8. If false, set 'breakable' to false
Hint: show details
Inside the 'if-then' statement, set the 'breakable' variable equal to
false
.
breakable = false
Hint: show image
Hint: show code
9. Add an 'else' to your 'if-then' statement
Hint: show details
Type the word 'else' on the next line and hit 'return/enter'.
else end
Hint: show image
Hint: show code
10. Make the Tool the parent of 'anim'
Hint: show details
Set the parent of 'anim' equal to 'Tool'. This will cause the animation to play.
anim.Parent = Tool
Hint: show image
Hint: show code
11. Wait 0.5 seconds, outside the 'if-then-else'
Hint: show details
After
the end of your 'if-then-else' wait 0.5 seconds.
wait(0.5)
Hint: show image
Hint: show code
12. Check if 'breakable' is true after the 'for-loop'
Hint: show details
After the end of the 'for-loop' use an 'if-then' statement to check if 'breakable' is true.
Don't forget to hit the 'return/enter' key to get an 'end' statement.
if breakable == true then end
Hint: show image
Hint: show code
13. Move the line that destroys the block into the if-then statement
Hint: show details
Move the line that calls the 'Destroy()' function on 'myTarget' to be inside the if-then statement.
myTarget:Destroy()
Hint: show image
Hint: show code
14. Test it out!
Hint: show details
Test out your game to see if your pickaxe can break the blocks when you hold down the mouse button for long enough.
×
×
Provide your email address for immediate project access
Email
Check your email for instructions on how to create a full DA account