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 functions for each color. The solution is in the code box below.

  1. Playtest and check that all three colors loop without stopping.
Troubleshooting Tips
  • 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).

Rewarding Players Points

Now that the part loops through the colors, it needs to give 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.

Get Player Points and Part 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. To get the current color inside the part’s Color property, type:
local currentColor = pointPart.Color
  1. Next, store that player’s leaderboard by typing:
local playerStats = player:FindFirstChild("leaderstats")
  1. Create a variable to get the player’s Points value, a child of their leaderboard.

Give Players Points

Next, you'll type an if statement to give different values of points based on the color of the part.
smallPoints Gives some points
largePoints Gives many points
losePoints Takes away points
  1. Code an if statement that checks if the current color is blue and if so, adds the number inside smallPoints to the player’s points. Remember because playerPoints is an IntValue, it’s changed by typing .Value after the variable name.
  1. To check for the second color, create an elseif condition for green and add the larger points variable to that player’s points.
  1. Use an else statement to remove points if pointsPart was neither blue nor green. Remember to subtract rather than add this time.
  1. Destroy the part after the if statement so that the script only runs once, and doesn’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 Player Feedback

The PointPart works correctly, but players might not realize it's working unless they look at their leaderboard. To show it works, you can add colored particles that follow the player after PointPart was 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. This is another reason why the colors were stored in variables so they can be used again here. Each particle will be attached to the player before it’s destroyed.

  1. In givePoints() after the part was destroyed, create a new ParticleEmitter instance. Make sure the instance name is spelled exactly as shown in the quotations.
  1. To let players know which color they hit, you’ll set the particle’s color property to a new color sequence, a type of color used by Particle Emitters.
  1. So the script can find where the player is physically in-game, use the player’s character. To store that character, create a new variable and set it equal to player.Character.
  1. Now that you have the character, you can parent the particle to that player’s head.