What does this mean? And what does it do

What does it mean, when you just do:

local var

Instead of:

local var = true

I’ve tried to ask people but I really can’t seem to understand.

1 Like

Think of that like it’s

local var = nil

You can write anything into it: Numbers, Strings, Tables, Events, whatever. It’s just empty.

1 Like
local var

is basically the same as

local var = nil

People use it so they can assign it as a global variable later in the script

local data 
local yes, no pcall(function()
 data = DataStore:GetAsync(key)
end)

if yes and data then
  player.Stat = data
end
5 Likes

I believe this is just an empty variable, which defaults as a nil value

If you were to put this in the command bar:

local Value
print(Value)

There was no value assigned to that variable, however if you do this:

local Value = true
print(Value)

It will print true, cause there was a defined value assigned to the variable which would be considered as a Bool (Or true)

My Forum is broke k cool

It basically just sets nil into that variable, it typically is used when you don’t need a default value in the variable because it’ll be set later on, or you just want to shorten local var = nil

An example would be putting a connection in a variable to disconnect later

local event

event = script.Parent.Touched:Connect(function(hit)
    print(hit.Name)
end)

wait(5)

event:Disconnect() --The touched even is disconnected now so it wont print anymore

So it’s basically so you tell the script it’s there, but you assign the data to the variable later on?

Yes, and everytime that lot of code is run it defaults back to nil so it doesn’t get the data of the previous thread.

Basically all you need to know is that if you are going to use global variables it will be useful to implement this into your code. (although it doesn’t really have much use)

Thanks, I’m trying to get into datastores, and it’s really hard for me to learn that even tho other things is easy to learn.