Scripting Lesson 002: Auto-Running Scripts

Hello scripters! Welcome back to our scripting lessons. Today we will be talking primarily about how to make a script run all by itself without any trigger function like PlayerAdded or OnTouched. We will also talk about Color3 a little bit. Thanks to anyone who decided to do the special exercises at the bottom. Just to let you know they are not homework assignments for we do not give homework here at IT. They are simply extra practices to help you understand the lesson to a deeper level.

So for starters, I will show you a script that I made for a disco brick. It uses something called Color3. You know the 64 colors you use to color your bricks? That is BrickColor, and can only be used to change a brick's color (obviously) Color3 is basically setting a red, green, and blue value to a color, kinda like coordinates for a specific color. The color possibilities are endless when it comes to Color3, but this can be used to change the colors of both bricks and lights, but with bricks you can only do this using scripts.

So as you can see, in line 1, there is "while true do". This basically means that when the server starts, the script begins. This also runs in a loop, so the script will never end (if you want it to end, we will discuss that in another lesson very soon). FYI, The reason why the wait time is 0.46875 seconds is because I scripted this to be able to go along to songs with 128 bpm. 60/128=0.46875. Now you'll want to make sure that if you do this, that you have a light in your brick. This is how it should be layed out:

And then I set the coordinates for the colors I wanted the brick and light to be when the wait ended. (Tip: If you want to give yourself a reminder or for any other reason, you want to write in the script, just put two hyphens before you type or else it can damage the script. You will also notice that I wrote Color3.new, which is mandatory when changing a color of a brick.

If you read our building lessons, you remember how coordinates of a brick go from (x, y, z). This "Color Code" goes from (r, g, b) or Red, Green, Blue. So if you want your brick primarily red, set your red value to 255 (highest it will go). If you want to make a purplish color, you also increase your blue value to a higher number and decrease the red value a little. It can be tricky to get ahold of so you can always go into your spotlight properties and toggle with the color pad. There it will tell you the "coordinates" for your color.

Thanks for tuning into this short, but helpful lesson. Our next lesson will be uploaded in the next day or two and will cover making locals, more functions, and how to make a leaderboard.

Extra Practice- Make a script that when you touch a brick, it changes its color

Challenge- Make a script that when you click a button, it changes another bricks' color

Extra Challenge- Make a script that when you touch a brick, it changes its color randomly (I don't expect all of you to be able to do this for we have not discussed it yet), but if you do it, I will consider you for a promotion to Development Trainee.

-Domswolf