Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What does it mean when some variables are defined without an "=" ?

Asked by 5 years ago
Edited 5 years ago

I'm new to coding and so while trying to learn what certain commands I have seen a few scripts in which there will be a line like

local player

or

local humanoid

I wasn't sure if they had a purpose so I tested those scripts removing these lines and the script would immediately crash. What is the purpose of these, and what does it mean when they have no "=" to define them as something else?

0
writing "local player" is the same as writing "local player = nil", it's only purpose is to assign the variable Vulkarin 581 — 5y
0
No problem! User#21908 42 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Those are variables that will be referred to later. Here is a section of my scripts that I apply it in:

local mainDataTable  -- here I name the variable

local success, message = pcall(function()

        mainDataTable = mainDataStore:GetAsync(specialKey) -- here I assign it a value. If I had done local mainDataTable inside this function then the rest of the script would not be able to use it. So I set the variable first then gave it a value

end)

Hope this helps and have a great day scripting!

0
That explains a lot, thank you! SpookyBo1 -1 — 5y
Ad

Answer this question