For example, I came across a teleportation script:
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid ~= nil then
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(workspace.TeleportParts["BluePart"].Position) + Vector3.new(0,3,0)
end
end)
Why is ‘~= nil’ being used here? Because I could just write:
The true purpose of ~= nil is the usage of cases when false should be used. Because when you reference something such as GuiObject.Enabled, it will return false if it’s not visible.
Thus avoiding the issue, it can be done like this: Extracted from previous script testing session.
if not properties then
if ui.Visible ~= nil then
ui.Visible = not ui.Visible
elseif ui.Enabled ~= nil then
ui.Enabled = not ui.Enabled
end
else
for property, value in next, properties do
if ui[property] ~= nil then
ui[property] = value
end
end
end