How to start scripting

I find many devs having trouble starting scripting although I do not grade A, I do know the ropes. I find that most people just copy from tuts instead of learning. This tut is the help people start making their own og scripts. Or at least help you understand scripts and what’s going on
This tut will talk about

  • Events
  • Tables
  • While loops
  • If statements
  • Printing
  • Functions
  • Variables
Printing

We can start off with scripting first insert a script into the workspace

Another thing you will have to do is open the output window.

Now the first thing you will see in the script is this line
print(“Hello World!”)
And if you push to run you should get this in the output
Hello world
Let’s break this line down

first you see the wordprint
This is is a function. What’s a function?

A function is a way of making code run with a parameter for example the Hello World is a parameter. A parameter is basically properties within the function.
Now similar to a property we can change it
Let’s change it to this
print (“MyHeadisMelting is Awsome”)
Now if we print we should get this
MyHeadisMelting is Awsome
Now there’s one more thing we need to know. there are 3 types of main properties in code (there are more but these are the most important)

  • Boolean = This is true or false
  • A string = a set of characters that can be printed (Note: you need " " to do this otherwise it won’t work)
  • Numbers = Things like 1 2 and 3 (You don’t need " " to use it )

That’s it, for now, a good exercise is to print multiple messages

Variables

These are ways to put parameters in a short word sort of like functions.

to use one you have to write something like this
local message = “Hello!”
Now to use these you have to put them in a parameter.
print(message)

Then if we run it the output should be
Hello!

Now you learned how to use variable now try using different parameters for exercise’s

Functions

Now making a function is like making a variable

too make a variable write this
local function
Now we need to name our function
local function print_this()

now one thing we need to do is add a parameter a way to do that is to use variables in our function

local function print_this(text)

One more thing you need to do is to add an end like this end will tell us where the code will end
local function print_this(text)

end

Now let’s tell our function what to do
local function print_this(text)
print(text)
end

now the way to use a function is toowrite it
print_this()

Now add the parameter in the ()
print(“Hello!”)
you should get this output
Hello!

Now try to make a different function with different things and parameters.

While

This one will be a bit short

The whole use of the While function is to make something go on for a long time.
to use it you have to write it

while true do

end

Then we add the code that will repeat
while true do
print(“Hello”)
end

then the output will be this
Hello Hello Hello Hello Hello
you get the point

If statments

If statements are ways to keep code from running unless a parameter is meet

to start you must have a variable to have a parameter to meet.

local parameter_num = 2

Now we need to tell the script what needs to happen first (note: you need 2 == not just one)

if parameter_num == 2 then

now we need to tell the script what happens when the parameter is met

if parameter_num == 2 then
print(“parameter is met”)
end

one other thing we can add is an else statement this tells the script what else it can do if it is not met

if parameter_num == 2 then print("parameter is met") else print("parameter isn't met") end

another type of else is elseif
it’s another way to add a different reaction if a different parameter is met.

if parameter_num == 2 then
print(“parameter is met”)
elseif parameter_num == 4 then
print(“parameter is met”)
else
print(“parameter isn’t met”)
end

thats is for the if statements.

Tables

Tables are a way to keep multiple variables in one variable and the ability to pick and choose

The way to use tables is to start off is with the way is variable starts

local table_num =

Now we add the variables with these {}

local table_num = {1,2,3}

Now we can use a print of one of these numbers only with a special parameter. Using this [ ]

print(table_num[1])

that’s it for now.

Events

Out of all these exercises, this will be the most interesting since we have to play for this one.

put a script into a part for this one

To start we need to relate to who is event will affect.
One thing I need to talk about is the hierarchy this is basically it

  • Parent = the thing that the child is in
  • Child = the things that under the parent
    I hope this helps

in the script, we must type this variable

local Parent = script.Parent

Then we must make a function ill make a quick one that changes the CanCollide I will also use a wait function that makes the script wait.
local function cancollide_change()
Wait(10)
Parent.CanCollide = false
end
end

Then we must choose which event to do. (like built-in functions there are multiple built-in events)

For this exercise, I chose touched.

We start with this line
Parent.Touched:Connect()

Now the only thing we need to do is add the function name in the ()

Parent.Touched:Connect(cancollide_change)

Now if we play the door should be can collide false after 10 secs from touching it.

I hope this helps :smiley:!

6 Likes

That topic is fine. Its just you should be a bit more descriptive like adding pictures. For each element of scripting you put should have a picture. Like when you have the tables. You should put a script using tables and explain what its defining. Lastly, you forgot some part of the scripting such a parameters and booleans.

4 Likes

should talk about objects also, and try to make the document more clean and appealing for others

I don’t see any purpose for this whatsoever. There’s already numerous threads for noobs that cover the basics like yours:

Not to mention, the devhub has tutorials covering just about everything at this point: Scripts | Documentation - Roblox Creator Hub I don’t see a need for these ‘tutorials’ other than to rack up post count.