I was watching a scripting tutorial and I know what nil means but what does it mean in this sentence and how can I use it in code?
The operators ~
(not) and =
(equal) is checking whether something is not equal to something else.
For example, if you were using the FindFirstChild method to find a particular child, the FindFirstChild method would either return the first child it found with the given string, or, it would return nil if it had not found a child with the given string.
It is important to check whether the FindFirstChild method returned something that is not nil; if the method did return nil, it would error later on in the script.
local child = workspace:FindFirstChild("Part") if child ~= nil then print("child exists") else print("child does not exist") end
Another way of doing this is to exclude the ~= nil
part; it will still check if child
is not nil or false.
local child = workspace:FindFirstChild("Part") if child then print("child exists") else print("child does not exist") end