THIS IS PART TWO OF LEARNING LUA PLEASE START AT PART ONE
Now that we know about clients and servers, let’s start learning about coding
I will be showing examples of everything.
This thread includes:
- Prints
- Comments
- Variables
- Changing Part Properties Through Script
Prints
Prints are very basic, to print is to display a message in the output, it is only visible to the server. Prints can also be shown in the Developer Console, you can only use it when you are playing as the client. Here’s an example of a print
print("This message is only shown in the output.")
Output Result
12:00:52.594 This message is only shown in the output - Server - Script:1
Comments
Comments are very basic, you use comments in a script, comments are not put out in the output like print, comments are only visible to the server, to use comments put – and type your comment. You can use Comments for organizing for example:
local variable = print("Hello World") --Prints Hello World
variable --Variable Is Being Called
This can be useful if you backtrack to your scripts or if you are making a free-model / open-source.
Variables
Variables are very important! You will use them in every script you program, variables are used to hold information, for example, you can store a part inside a variable:
part = game.Workspace.Part
Using variables, I stored the part. To make a variable you first name your variable, then you add an equivalent sign to show what it is equivalent to, so the part is equivalent to game.Workspace.Part which leads to the actual part stored in the Workspace. To call a variable, you just say its name for example:
part = game.Workspace.Part
part
this obviously doesn’t do anything because we are specifying the part’s place in the workspace, we will be using variables soon in this thread.
Part Properties
To see the part properties you just press the part and look in the properties, the properties in the part is what you can change in a script.
Let’s say you want to change your part into another color, we would first
store the part in a variable, then call the variable and change it by using the equivalent sign. Example:
part = game.Workspace.Part
part.BrickColor = BrickColor.new("Really red") -- This is changing the color to red
You can change other things as well
part = game.Workspace.Part
part.Anchored = false --This is unanchoring the part.
This changes if it’s anchored or not.
part = game.Workspace.Part
part.Transparency = 2
This changes the Transparency
My point is, you can change a part’s properties using a script.