UevKF8zjRV_WEtpJsXhr
We use cookies on this site to enhance your user experience

  1. On your own, code a while true do loop that changes pointPart to the color variables you’ve created. Don’t forget to use wait() between colors.

  1. Playtest and check that all three colors loop without stopping.
  • Check that the while loop is at the bottom of the script, below the Touched event. If the loop is not at the bottom, it’ll keep other parts of the script from running correctly.
  • Check that each color inside Color3.fromRGB() is correctly written. There must be three numbers between 0 and 255 separated by commas, like (255, 50, 0).

Giving Players Points

Because each color gives a different amount of points, the script will use an if statement to check what color is active when touched and give points based on that color.

Find the Current Color

Before the player can be awarded the right amount of points, you need to set up variables to capture what color the part was when the player touched it and the amount of points the player already has.

  1. Find givePoints()
  2. Replace your testing message with a variable for the current color of pointPart.
  1. Next, add a variable for the player’s leaderboard.
  1. Now add a variable to get the player’s Points value, which is a child of their leaderboard.

Give or Subtract Points

Next, you'll use if and elseif to give or subtract points depending on the color of the part when touched.
smallPoints
largePoints
losePoints
  1. Inside givePoints(), beneath the variables, use an if statement to check if the current color is blue and if so then add smallPoints to the player’s current points value.
  1. To check for green, add an else if condition. If green, then add the largePoints variable to the player’s points.
  1. Use an else statement to subtract points if pointsPart was neither blue nor green.
  1. Lastly, destroy the part after the if statement so that the script can’t keep giving out points.
  1. Playtest and check that each color gives points as expected.
Testing Every Condition

When working with if statements with multiple conditions, it’s important to test that every elseif and else statement works. It’s possible to test one statement, think everything works, but then discover later on there’s a bug in one of the statements that could have been caught earlier.



Giving Players Feedback

The PointPart works, but players might not notice something happened unless they happen to be looking at their leaderboard. Fix that by creating particles when the PointPart is destroyed.

Adding feedback when players use a part, like sounds, shakes, or particles, makes interactions with objects more satisfying to players.

Create a Particle Effect

The particle effect will be the same color as the part when touched. Since the colors were stored in variables, it’s easy to reuse them.

  1. In givePoints() at the bottom, create a new ParticleEmitter instance. Make sure the instance name is spelled exactly as shown.
  1. ParticleEmitters use color sequences to control their Color property. Create a new ColorSequence and pass in the current part color.
  1. The particle will need to be parented to player that touched it. Create a variable to get the player’s Character model.
  1. Using the character, you can parent the particle to that player’s head.