Before I say anything I need to tell you that there is no shortcut when learning how to script
Some people may learn faster than others and it took me 1 year to fully learn most of each endpoint. Like what WingItMan said, donāt set your scripting standards so high as youāre new.
Print Function
print("String here")
Now you might be asking why do I need ""
inside the parenthesis? The reason is to define that youāre using a string value. If it was a number value you could just say 1
without using "1"
.
Now, letās try to print in the console āHello, World!ā.
Answer:
print(āHello, World!ā)
Loops
There are multiple types of loops here.
While - do loops
This is the most common loop for you. While [Argument] Do means whatever code you put inside the loop it will keep on running until the Argument Statement is no longer true.
Example:
while true do
print("Hello!") -- Hello everyone!
wait() -- I'll tell you why later why you need this
end
Of course, if you keep a while true do
loop without a wait() function or a wait system then your Studio would crash as youāre trying to loop something over and over in 0 seconds.
Here is an easy wait of adding a wait() inside a while true do loop
while wait() do
-- Code here
end
For i loops
For I loops have 3 arguments: Starting number, Target Number, Increment (Default 1)
For i loops should be used for times that you need to repeat something over and over a specific amount.
Example code:
for i=1, 5 do -- Count up to 5
print("This message was said a total of " .. i .. " times!")
end
wait()
The wait() function is to yield the script an X amount of time. If you leave X blank it will wait 0.03 seconds I think. The X must be a number value and it is counted in seconds.
Example:
print("Let's wait for 1 second!")
wait(1)
print("We waited for that long? Like omg #WaitingIsSooooLong")
If Statements
IF STATEMENT THEN
This is when you want to check if a statement is true and want to run code.
Example:
local CanPrint = false
if CanPrint == true then
print("We can finally print!")
end
ELSEIF
Elseif statements allow you to run multiple if statements inside 1 if function. If the first If statement is not true then it will move onto the next and so on and so on
Example:
local Number = 2
if Number == 1 then
print("It's 1!")
elseif Number==2 then
print("It's 2!")
elseif Number==3 then
print("It's 3!")
end
ELSE
Else will only activate if all IF statements are not true.
Example:
local CanPrint = true
if CanPrint == true then
print("We can print!")
else
print("Seems like the party pooper is here")
end
This is a very quick introduction to Lua.
Please reference from a professional video tutorial or the Roblox wiki.
I highly recommend you use the Wiki. If you need further down the line reference code I recommend @alvinbloxxās youtube videos
Tho, what I would reccomend is him explaining more on youāre coding i.e. explaining what this part does and why in the video.