Project 387: Lemonade Tycoon

17. Program to see if a humanoid touched the button

If we don't have this check, any random brick could fall on the button and trigger a lemonade stand purchase!

Starting point file for this challenge

Steps

1. Use a "character" variable to keep track of whatever hit your button

We'll keep track of whatever thing hit your lemon with a local variable. We'll call the variable "character" and then set it equal to "other." (Remember, "other" is whatever "other" object ran into your button.) 

local character = other

2. Adjust the code to keep track of the parent of that object

Roblox is kind of silly - when an object is touched by a character, the object thinks it only got touched by the arm, and not the entire body. 
 
If we continued with this code, we wouldn't be able to access the leaderstats, because those are being stored in your player... not specifically the player's leg. 
 
In Roblox, a character's body is a parent of their arms and legs. So, make your "local character" equal to the "other.Parent." 

local character = other.Parent

3. Search the character object for a "humanoid" object.

We still have to double check that it was a player that hit your object. All players in Roblox have something called a "Humanoid" on them, and it holds all the information of your player. 
 
So, tell your "character" to run a function called "FindFirstChild" with the parameter "Humanoid" 

character:FindFirstChild("Humanoid")

4. Keep track of the humanoid object by saving it as a local variable

Cool, your code found the "Humanoid" object, but we still have to keep track of it. 
 
Let's do that by creating another local variable called "humanoid" and setting it equal to the results of that function you just called. 

local humanoid

5. Create an if-statement checking if it was a humanoid that touched the powerup

Now we can finally write an if-statement that checks if humanoid is true or not. 

if humanoid then

6. Hit return to create an "end" to the if-statement

Anything written in between the word "then" and "end" will be the "then" blank of your if-statement.