Tutorial on basic things you need to know as a beginner to start scripting

Hello everyone!

I hope I choosed this category correctly, because this is educational content, but for the most beginners. Anyway, before report, please tell me if this is wrong category. I spent a lot of time writing this article, thanks.

So let’s get started. In this tutorial, I’m gonna explain you step by step things that will help you in the future. If tutorials on YouTube are too complicated or not clear for you, in this article I will try to help you get into scripting as simply as possible.

1. Explorer and Properties.

This is the first thing you should know about. If you know how to work with these two windows, then you can skip this step:

In Explorer (up window) you can see some services and what’s located in them. For example: Workspace, Players, Lighting etc. Every service is responsible for something in game. Workspace is a 3D world, Players is service which stores information about players, Lighting is server where you can set up shading etc.

So if you built a map for example which you see in your game, it stores in Workspace. You can find any item in services you added. Baseplate stores in Workspace. But what about Properties?

Properties let you see what setups and parameters you have for anything you can select in Explorer. For example, if you select part, you can change its color/material/size/position and other things in Properties. You will always need properties in scripts.

Now you can go and play around with stuff you have in Explorer by Properties.

2. Local players and Server.

No, it’s not scripting yet. Before you start you should learn that there are three types of scripts:

image

The two main one are Script and LocalScript. You don’t need ModuleScript at the moment, you will learn it yourself in the future.

For your understanding the whole game you join is a server. Like when you join a friend, you join a server. Server has players in itself. They also appear in Players service. Server is like a big house where residents are players. Players also can be named Clients.

Scripts are used for server changes. As example: you wrote Script which changes part’s color. The color of part will be changed on server and everyone will see new color.

Here is example of Script and how will it work:

I wrote a simple script which changes part’s color to black throught Script. As you can see all players see part’s color black. Changes were on server, so server now have this part as black. But what if we will make LocalScript for one player.

Here is what happens:

Left one player has LocalScript changing part’s color and right one doesn’t. That means only left player sees new part’s color. Server also doesn’t have any changes:

Local scripts are used for gui eg. When buttons work for each player, but not for the server. Sometimes we will need to transfer information from a player to another player. For example, when you’re making shooter and weapon has to kill another player for everyone, not just for player who shoots, you will have to transfer information to server first. For this you will need thing named RemoteEvents.

3. Starting to write script.

This is all good, but how do we start writing scripts and what kind of “orthography” it has? Let’s make empty Script into service named “ServerScriptService”. This service is the most safe and intended for Scripts (not LocalScripts). Delete everything that’s in your script and write first word “game”

No capital letters

image

Let’s say that game is something like our Explorer. We now need to get something through script. It looks like computer folders when you’re searching some file (eg. C:\Users\Player\Pictures). But here is you always search something in “game”. All services, all datas, all players and values. Everything.

Let’s try to get Baseplate for example.

game.Workspace.Baseplate

Now we got path to out Baseplate throguh Script. Open Properties of Baseplate and choose one you’d like to change. For examples I want to change Transparency.

game.Workspace.Baseplate.Transparency = 1

Baseplate will have Transparency value on “1” everytime when server launches.

But not always you can write values like that. To make sure how to properly write it, go to developer.roblox.com and search what type of property you wanna change.

Let’s try to change Color (not BrickColor).

Here’s what article says:

Value type is something how you change propertion. It might be a bit difficult for you right now, but let me try to explain. First write property you want change:

game.Workspace.Baseplate.Color

After “=” we need to write Value Type

game.Workspace.Baseplate.Color = Color3

And now we should add “.new()” to Value Type

game.Workspace.Baseplate.Color = Color3.new()

And between parentheses write RGB value of your color:

game.Workspace.Baseplate.Color = Color3.new(0, 0, 0) -- black color

It can be tricky at first, there are Value Types like Enum for example. It’s used for materials and others. Explore developer.roblox.com during your first scripting.

4. Events and Functions.

And this is probably main thing for scripts. What’s events? Events is when something happened. For example: players touched part, player clicked button etc. We can check through script did it happen? But what do we do with that? We add functions. For example: even of part touching happened and function will work and do something, because event happened. (I’m bit bad in english to explain this, but I hope you understand)

Better I will show at practice. Let’s make an even, if something will touch our baseplate. To see what events you can add to the type of thing you have, you can open Object Browser here:

Baseplate is a “Part” so we need to search Part at the left side of object browser. Events have this label: image

I found Part and Event “Touched”:

Let’s back to our script. Write events after “.” like path.

game.Workspace.Baseplate.Touched

We added event, but it’s useless right now. Now let’s make it changing baseplate color after event happens. So basically when baseplate will be touched, it will change its color.

To make this we need add function to event.

game.Workspace.Baseplate.Touched:Connect(function()

Andddd press Enter. Now you have something like this:

game.Workspace.Baseplate.Touched:Connect(function()
	-- space where we will write what will happen after event happening.
end)

Now everything we have to left is just write something that should happen after event happens between function() and end)

I made it change Baseplate’s color to black when it gets touched:

game.Workspace.Baseplate.Touched:Connect(function()
	game.Workspace.Baseplate.Color = Color3.new(0,0,0)
end)

5. Loops.

Every programming language has three main loops. Lua is not exception. Let me introduce you all of them. Loops are needed when you need something being repeated. For example: make part changing its color every 5 seconds infinitely. But there are different types of loop which work differently.

    1. while

This loop needed when you need something repeat until something changes. Example:

while game.Workspace.Baseplate.Color == Color3.fromRGB(0,0,0) do
	
end

This loop will do something while Baseplate’s color is black, but when Baseplate will change its color, loop will be stopped.

Note, when you need to check something use “==” instead of "="

You can make this loop infinity that nothing will stop it. You can write this:

while wait() do
	
end

Between parentheses you can write time in seconds which should past to make loop repeat again. If there is no time, it will repeat instantly.

If you want be something looped, just write you script between do and end.

    1. repeat/until

Unlike while this one loop allows you to loop something until something changes/happens. Example:

repeat
	print("Hello!")
until game.Workspace.Baseplate.Color == Color3.new(0,0,0)

This script will write “Hello!” until baseplate’s color will be black. Then it stops work.

    1. for

Probably the hardest loop in my opinion. This loop will do something for certain number of times. For example you need something to repeat 5 times.

for value = 1, 5 do
	print(value)
end

To make you understand the variable “value” will have a value which is the same as loop’s repeat. Like if your loop repeats 4th time, “value” will be 4.

To be simplier it’s like a gif with frames, but all difference which has loop’s “frames” is only “value”'s value.

6. Other useful things you will always need.

    1. Wait()
      Between parentheses you need to put amount of seconds your script needs to wait.
    1. Print()
      Between parentheses you need to put something that your script will write in output. If you need it to be text, be sure to put text between “_”.
    1. local
      Instead of making big text like game.Workspace.Baseplate you can make it local local InsertAnyNameYouWantHere = game.Workspace.Baseplate and next time if you will need baseplate you can name it in script by local name you gave it like this: InsertAnyNameYouWantHere.Color = Color3.new(0,0,0)
    1. Output
      Be always sure you enabled output:

      Output says you if your scripts have any errors and what errors exactly.

7. Resources.

I highly recommend you to read articles on developer.roblox.com because this is where I explore new stuff in scripting myself.

You can also watch some YouTube tutorials in the future.

If you have any issues there is very useful category named #help-and-feedback:scripting-support where people usually try to help each other.

8. Finale.

I spent all day on this tutorial

I wrote about what will help you start scripting now. You already in all seriousness can go to studio and write your first script. It can be difficult at first, but never give up. Yesterday you just saw seeing this tutorial, tomorrow you are creator of popular game. I would also like to saw biggest thanks my mentor and the closest person who also helped me get into scripting a few years ago, but sadly he doesn’t allow me to tag him. If you have any questions or issues, you can always reply to this topic, I will try to help everyone. I hope this tutorial was helpful.

Have a nice day everyone! :smile:

53 Likes

wait() is deprecated, use something else or use task.wait()

4 Likes

So wait() doesn’t work anymore? I just found topic about it, but it doesn’t say it can’t work anymore.

1 Like

no it still works, why would roblox break old games

the task library deprecates wait(), spawn(), delay()
they are much better

EDIT: deprecated means it won’t be updated anymore, and that there is most likely a better solution

2 Likes

You forgot .Touched here, and you also should use workspace instead of game.workspace. Even in the latter, workspace should be capitalized.

3 Likes

Oh damn, thank you for correcting me, i was so sleepy writing this. Also I think you can use game.Workspace too

1 Like

very nice tutorial! would be useful for newbies

4 Likes

game.Workspace or workspace

script.Parent - reference to the object in which the script is nested