The Basics
To start scripting, we'll need to open a script. Insert>Object>Script in Studio.We'll start with changing properties. Remember that Explorer contains everything in your game. The Properties windows provides settings for everything in explorer. You can access the contents of both of these via scripts.
Your First Script
To begin, we'll kill your character. There are many ways to do this.
First, we need to find the player in the game. You can use Explorer to find it. Remember that everything is in the game. Remember also that the bricks and scripts of the game, including those of your player, are in the Workspace. So, your player is in game.Workspace. Everywhere in Explorer that you see a "+", you'd put a "." when going to something inside of it.
Inside game.Workspace is your character, and inside your character is a Humanoid. The Humanoid contains many things for your character. (Check them out in the Properties menu!) One of those things is your Health. When you spawn, it is set to 100. You die when it is at 0. So, we want it to equal 0. To assign values in Lua, you simple use the "=" symbol.
So here's your first script! Note that I used Telamon as an example. You can change the name to any user.
game.Workspace.Telamon.Humanoid.Health = 0
Your First Script
To begin, we'll kill your character. There are many ways to do this.
First, we need to find the player in the game. You can use Explorer to find it. Remember that everything is in the game. Remember also that the bricks and scripts of the game, including those of your player, are in the Workspace. So, your player is in game.Workspace. Everywhere in Explorer that you see a "+", you'd put a "." when going to something inside of it.
Inside game.Workspace is your character, and inside your character is a Humanoid. The Humanoid contains many things for your character. (Check them out in the Properties menu!) One of those things is your Health. When you spawn, it is set to 100. You die when it is at 0. So, we want it to equal 0. To assign values in Lua, you simple use the "=" symbol.
So here's your first script! Note that I used Telamon as an example. You can change the name to any user.
game.Workspace.Telamon.Humanoid.Health = 0
But what if Telamon isn't in your game? Then, this script won't work, and it will error, since Telamon doesn't exist in game.Workspace. You can't access values or items that don't exist using scripts. But, if you change it to your name, save, and play the game, your character will reset!
Names with Spaces
But what if you have a name with a space in it, like some users do? If you try using
game.Workspace.That Guy.Humanoid.Health = 0, the script won't work. Fortunately, there's an easy solution. If there is an item in your place with a space in its name that you want to access through a script, put its name inside of quotation marks inside of brackets. For example, game.Workspace["That Guy"].Humanoid.Health = 0.
[TIP: You don't need to type game.Workspace in RBX.Lua. You can just type workspace! For example, workspace.Builderman.Humanoid.Health = 0 is the same as game.Workspace.Builderman.Humanoid.Health = 0. This trick doesn't work with Lighting, Players or any other element directly inside of game (services), though.]
More Properties!
Now, let's practice changing some other properties. Want to make a brick that you can walk through? We'll change the CanCollide property. In the Properties window, there's a checkbox. If it's checked, it is true. Otherwise, it's false.
workspace.Part.CanCollide = false
We can also change text values by putting the desired text in quotation marks:
workspace.Message.Text = "I'm scripting!"
Semicolons can be used in Lua, where you would often put a line:
game.Lighting.TimeOfDay = 6; workspace.Base.Transparency = 1
The above script changes the time of day and makes the base invisible.
You'll learn more about data types soon. For now, head over to the next lesson.
Names with Spaces
But what if you have a name with a space in it, like some users do? If you try using
game.Workspace.That Guy.Humanoid.Health = 0, the script won't work. Fortunately, there's an easy solution. If there is an item in your place with a space in its name that you want to access through a script, put its name inside of quotation marks inside of brackets. For example, game.Workspace["That Guy"].Humanoid.Health = 0.
[TIP: You don't need to type game.Workspace in RBX.Lua. You can just type workspace! For example, workspace.Builderman.Humanoid.Health = 0 is the same as game.Workspace.Builderman.Humanoid.Health = 0. This trick doesn't work with Lighting, Players or any other element directly inside of game (services), though.]
More Properties!
Now, let's practice changing some other properties. Want to make a brick that you can walk through? We'll change the CanCollide property. In the Properties window, there's a checkbox. If it's checked, it is true. Otherwise, it's false.
workspace.Part.CanCollide = false
We can also change text values by putting the desired text in quotation marks:
workspace.Message.Text = "I'm scripting!"
Semicolons can be used in Lua, where you would often put a line:
game.Lighting.TimeOfDay = 6; workspace.Base.Transparency = 1
The above script changes the time of day and makes the base invisible.
You'll learn more about data types soon. For now, head over to the next lesson.