How do i use "print()"?

print(...)
Displays all values in either Studio and/or Roblox Developer Console

... means any number of values past this point

Code sample:

local x = 1
local y = 2

print(x + y)

When a table gets output, Roblox Studio gets all values from the table and formats them.
Example:

print({})

-- Roblox Studio: {}
-- Normal Developer Console (F9 or /console in chat): table: 0x56ed5f1c3ae0e584

The reason we get table: 0x56ed5f1c3ae0e584 in the Developer Console and not Studio is because print tostrings all values passed. This means that print goes through all values and tostrings them. For example, 1 gets turned to “1”, nil gets turned to “nil”, and {} gets turned into “table: 0x[Memory address]”. You can also achieve the same behaviour when using userdata (newproxy() → “userdata: 0x[Memory address]”)

You can do this yourself using print(tostring({}))

You can also use metatables to change the output of tables.
Example:

local x = setmetatable({}, {
    __tostring = function()
        return "This will get displayed instead of {}!"
    end
})

print(x)

Learn more about print here!

1 Like