Skip to content
Engine

Data

Id

Generate identifiers of every shape, from GUIDs and sortable ids to human-friendly ticket codes and coupons.

PackageShared

Getting it

local Id = Engine:GetPackage("Id")

Overview

Id is a single place for every kind of identifier a game needs. Each function returns a string.

local Id = Engine:GetPackage("Id")

print(Id.Guid())            --> 3f0b6c1e-9a2d-4c1e-8f2a-5b7d9e0a1c3b
print(Id.Order())           --> 172774560012300000042  (sorts by creation time)
print(Id.Ticket())          --> K7QD-M3XP
print(Id.Reference("TRD"))  --> TRD-8HW2RN

Note

Random parts come from Roblox's Random, which is fast but not cryptographically secure. For secrets such as session tokens use CryptographyService.

Lengths and formats marked "config" below come from the package configuration and can be changed per game.

Unique ids

FunctionExampleNotes
Id.Guid()3f0b6c1e-9a2d-...A lowercase GUID from HttpService.
Id.Cuid()clw3x0k1a8f2k9q3mc + timestamp + counter + random (config), all base36.
Id.Cuid2()k1lw3x0k1b...Starts with a letter; fixed total length (config).

Random strings

FunctionAlphabet
Id.Random(len?)Base62 (0-9, A-Z, a-z).
Id.Slug()Base62, short (config).
Id.Base58(len?)Base58, without look-alike characters 0, O, I, l.
Id.Base62(len?)Base62.
Id.Base85(len?)Base85 with punctuation.
Id.Binary(bits?)0 and 1.
Id.Octal(len?)0-7.
Id.Emoji(len?)Random emoji.
Id.Custom(alphabet, len)Characters from your own alphabet.

Sortable ids

FunctionFormat
Id.Lexical(len?)13-digit millisecond timestamp + random base36 suffix. String order equals creation order.
Id.Order()13-digit timestamp + 8-digit counter. Strictly increasing within a server.
Id.Filename()Timestamp + - + random suffix.
Id.Request()Timestamp + random suffix.

Server and thread ids

FunctionDescription
Id.Machine()game.JobId on live servers, or STUDIO- + random in Studio. Same for the whole server.
Id.Process()Random id fixed for this Luau VM.
Id.Thread()Random id per coroutine, stable for that coroutine.
Id.Worker(workerId)w<id>-<timestamp>-<random>.
Id.Shard(shardId)s<id>-<timestamp>-<random>.
Id.Trace()32 hex characters.
Id.Span(traceId)traceId + - + 16 hex characters.

Human-friendly codes

These use an alphabet without characters that are easy to confuse (0/O, 1/I/L), so players can read them out or type them.

FunctionExample
Id.Ticket()K7QD-M3XP (groups and length from config)
Id.License(len?)9XKQ-2MPD-H7RT-W4NB
Id.Coupon(len?)QW7ZK2MD
Id.Reference(prefix?)REF-8HW2RN
Id.Temp()tmp-a8Kd02Lx9Q

Fake data

Handy for tests and placeholder UI.

FunctionExample
Id.Color()#3FA2C8
Id.IPv4()172.16.4.20
Id.IPv6()2001:0db8:85a3:...

Configuration

Defaults from DefaultConfiguration/Packages/Id28 settings
SettingDefaultWhat it does
CuidRandomLength8Random base36 characters appended to a Cuid.
Cuid2Length24Total length of a Cuid2.
SlugLength7Length of a Slug.
DefaultRandomLength16Length Id.Random() uses when no len is passed.
DefaultBinaryBits8Bits Id.Binary() uses when no count is passed.
DefaultOctalLength8Length Id.Octal() uses when no len is passed.
DefaultBase58Length12Length Id.Base58() uses when no len is passed.
DefaultBase62Length12Length Id.Base62() uses when no len is passed.
DefaultBase85Length12Length Id.Base85() uses when no len is passed.
DefaultEmojiLength4Emoji Id.Emoji() uses when no len is passed.
DefaultLexicalSuffixLength10Random suffix length after the timestamp in a lexical id when no len is passed.
MachineStudioIdLength12Random length of the machine id used in Studio, where game.JobId is empty.
ProcessIdLength16Length of the per-process id.
ThreadIdLength12Length of a per-thread id.
WorkerSuffixLength6Random suffix length appended to a worker id.
ShardSuffixLength6Random suffix length appended to a shard id.
RequestSuffixLength12Random suffix length appended to a request id.
TraceHexLength32Hex characters in a trace id.
SpanHexLength16Hex characters in a span id.
TicketGroups2Dash-separated groups in a ticket code.
TicketGroupLength4Characters per ticket group.
DefaultLicenseLength16Total characters in a license key when no len is passed.
LicenseGroupLength4Characters per dash-separated license group.
DefaultCouponLength8Length Id.Coupon() uses when no len is passed.
DefaultReferencePrefix"REF"Prefix Id.Reference() uses when none is passed.
ReferenceCodeLength6Characters after the prefix in a reference code.
FilenameSuffixLength8Random suffix length appended to a filename.
TempSuffixLength10Random length after "tmp-" in a temp id.