You Should Learn the basic function in Lua
For Example:
Comments:
-- Standard One Line Comment
--[[ Multi-Line Comment
OMG THIS IS A MULTI LINE COMMENT, I CAN TYPE MORE THAN ONE LINE
--]]
LOL -- What not to do
---[[ To Disable a Multi-Line Comment, add another Hyphen, This thing: -
local Var = "Hi"
--]]
Variables:
GlobalVariable = nil -- You set a Global Variable to nil if you want it to have no value
local LocalVariable -- Here you dont add anything
--[[
Global variables Can be used anywhere
Local Variables can be used within Range of the script
(Ex: if its inside a function, It can only be used inside the function)
--]]
local String = "Hello" --A string is usually Words, or Letters, and even Sentences
local Integer = 12 -- An Int is just Numbers
local Boolean = true -- A Bool is pretty much a true or false statement
wait(1) -- Waits for a certain amount of time (Deprecated)
--(Deprecated Means, No longer used, No Longer Supported, and is planned to be removed)
-- Use task.wait()
task.wait(1) -- Better at waiting (No throttling)
local function Example() -- a Function, runs code when called,
print("Hello!")
end
Example() -- Call the function by using its name, in this case "Example"
Loops:
When running loops, They will run until they are told to stop
There are 3 Main Loops, while
, repeat until
, and for
Looping = false
while Looping == true do -- a while loop runs for certain conditions, if the condition is not met, it wont run
-- NEVER FORGET TO ADD A WAIT, IT WILL CRASH YOUR SCRIPT
end
repeat
task.wait(1) -- Waits for 1 second before looping
until -- Repeats until a certain condition is met
A for
loop is the most complicated, It can Vary from Easy, to Confusing, Example of uses:
-- Simple Use
for index = 1,10 do -- Will run 10 times
task.wait(1)
print(index) -- Prints the Number the Loop is currently at
end
-- More Advanced Use:
for _,v in pairs(workspace:GetChildren()) do
if v:IsA("Part") then
v:Destroy()
end
end
What Not to Do
- Never name a Variable the same as a function, it will break the function the next time you use it
print = 12 -- Never do this
print(12) -- Running this will break since it has been assigned to something else