Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What does ~= nil mean, how can I use it, is there alternitaves?

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?

1 answer

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

1 comment

0

imagine "(not not child) == true" ????

This discussion is preserved as it was. New answers, comments, and votes are closed.