PcoWSkbVqDnWTu_dm2ix "> ">
We use cookies on this site to enhance your user experience

Oct 22 2019, 7:17 PM PST 2 min

In Lua, nil is used to represent non-existence or nothingness. It’s frequently used to remove a value in a table or destroy a variable in a script. For instance:

In Roblox, nil can also be used to clear an Instance object’s Instance/Parent|Parent value and effectively remove it from the game, although it may be possible to bring the object back. Consider this example:

-- Create a new brick
local part = Instance.new("Part")
-- Parent new part to the workspace, making it viewable
part.Parent = workspace 
-- Remove the part from view, but not from memory
part.Parent = nil
-- Part still exists because it's referenced by the variable 'part', so it can be returned to view
part.Parent = workspace 
-- Remove the part from view again
part.Parent = nil
-- Clear part reference so it gets picked up by the garbage collector
part = nil
  • lua
  • value
  • nil