getgenv
getgenv(): tableReturns the shared Cobalt execution environment.
Example
getgenv().message = "Hello"
print(getgenv().message)Based on the runtime bundled with Cobalt. These entries describe the inspected implementation, not a guarantee that every function has passed a live test. Compatibility entries call out partial implementations and placeholders.
58 entries
getgenv(): tableReturns the shared Cobalt execution environment.
getgenv().message = "Hello"
print(getgenv().message)getrenv(): tableReturns the runtime’s constructed environment table. This is not unrestricted access to every game script’s environment.
getexecutorname(): stringReturns "Cobalt".
getexecutorversion(): stringReturns the bundled runtime version rather than the desktop application version.
identifyexecutor(): (string, string)Returns the executor name and runtime version as two values.
Aliases: whatexecutor
local name, version = identifyexecutor()
print(name, version)loadstring(source: string, chunkName: string?): (function?, string?)Compiles Luau source without executing it. Returns a function on success, or nil and an error on failure. Compilation uses the desktop runtime and can time out.
local fn, err = loadstring("return 2 + 2", "example")
if fn then print(fn()) else warn(err) endqueue_on_teleport(source: string)Submits source to the runtime’s teleport queue. Execution in the next client depends on attachment and runtime availability.
Aliases: queueonteleport
readfile(path: string): stringReads a runtime workspace file. If a write is queued for that path, returns the queued content. Raises a file error when the runtime cannot read it.
writefile(path: string, content: string)Queues a file write. Replaces a pending write for the same path. Disk synchronization happens later, so keep the desktop app running until pending writes finish.
writefile("example.txt", "Hello, Cobalt")
print(readfile("example.txt"))appendfile(path: string, content: string)Appends to a pending write, or reads the existing file and queues its updated contents. A missing file can raise an error; create it with writefile first.
loadfile(path: string): (function?, string?)Reads and compiles a runtime workspace file. Returns the compiled function without calling it. Empty content returns a no-op function.
Aliases: dofile
Compatibility: dofile is an alias of loadfile here; it does not execute the file automatically.
local fn, err = loadfile("example.luau")
if fn then fn() else warn(err) endisfile(path: string): booleanChecks whether a file exists, taking pending writes and deletions into account.
isfolder(path: string): booleanChecks whether a folder exists, taking pending folder creation and deletion into account.
makefolder(path: string)Queues folder creation. Cancels a pending deletion for the same folder.
delfile(path: string)Queues deletion of a runtime workspace file. This scripting API is separate from the editor explorer’s Recycle Bin behavior.
delfolder(path: string)Queues deletion of a runtime workspace folder.
listfiles(path: string): {string}Returns tracked paths beneath the supplied prefix, including pending changes. It can include descendants beyond the immediate directory; ordering is not guaranteed.
getcustomasset(path: string): stringAsks the runtime for an asset URI for a workspace file. Flushes a pending write to that file first; failures raise an error.
request(options: table): tableSends an HTTP request. Required: Url (string). Optional: Method (GET by default), Body (string), Headers (table). Supported methods: GET, POST, PUT, DELETE, PATCH. Header names are normalized to lowercase; default User-Agent is Cobalt. The options table is modified in place. The runtime also adds client/device and game-session metadata headers. Returns Success and StatusCode, with StatusMessage, Body, Headers and Version when available. Success means an HTTP 2xx response.
Aliases: http.request, http_request
Use the capitalized Body field. Error responses can omit Body and Headers.
local response = request({
Url = "https://example.com",
Method = "GET"
})
print(response.StatusCode, response.Body)HttpGet(url: string, returnRaw: boolean?): anyReturns the HTTP response body by default. Passing false JSON-decodes the body. This helper explicitly sends a Roblox-style User-Agent rather than the default request User-Agent.
HttpPost(url: string, body: any, contentType: string?): tableReturns the request response table. The current wrapper passes a lowercase body field, while request reads Body, so the supplied body is not forwarded correctly.
Limited: use request({Url = url, Method = "POST", Body = text, Headers = {["Content-Type"] = "application/json"}}) instead.
WebSocket.connect(url: string): tableConnects through the desktop runtime to a ws:// or wss:// URL. Returns a connection with Send, Close, OnMessage and OnClose. Events expose Connect, Once and Wait. Close the connection when finished; connection errors can raise.
local socket = WebSocket.connect("wss://your-server.example/socket")
socket.OnMessage:Connect(function(message)
print(message)
end)
socket:Send("hello")
-- socket:Close()base64.encode(content: string): stringBase64-encodes a string through the runtime.
Aliases: base64_encode, crypt.base64.encode, crypt.base64encode, crypt.base64_encode
print(base64.encode("Cobalt"))base64.decode(content: string): stringDecodes a Base64 string through the runtime.
Aliases: base64_decode, crypt.base64.decode, crypt.base64decode, crypt.base64_decode
crypt.hash(data: string, algorithm: string): stringRequests a digest from the runtime. Algorithm names ignore case, hyphens and underscores. Recognized names: md5, sha1, sha224, sha256, sha384, sha512, sha512_224, sha512_256, sha3_224, sha3_256, sha3_384, sha3_512.
print(crypt.hash("Cobalt", "sha-256"))crypt.generatebytes(size: number): stringRequests the specified number of generated bytes from the runtime. The Luau wrapper does not establish their encoding or randomness guarantees.
crypt.generatekey(): stringReturns crypt.generatebytes(32).
crypt.encrypt(data: string, key: string, iv: string?, mode: string): (string, string)Delegates encryption to the runtime and returns the result plus the decoded IV from the response. Mode is required; recognized modes are ECB, CBC, OFB, CFB, CTR, GCM, CCM, XTS and OCB. An omitted IV is passed as an empty string.
Native key sizes, output encoding and mode-specific behavior are not established by the client wrapper; this reference does not promise interoperability.
crypt.decrypt(data: string, key: string, iv: string?, mode: string): stringDelegates decryption to the runtime using the same mode names as crypt.encrypt. Mode is required; an omitted IV is passed as an empty string.
lz4compress(data: string): stringReturns runtime-compressed LZ4 data; raises on runtime failure.
lz4decompress(data: string, size: number): stringDecompresses LZ4 data using the supplied uncompressed size; raises on runtime failure.
local text = "Hello, Cobalt"
local packed = lz4compress(text)
print(lz4decompress(packed, #text))cloneref(instance: Instance): InstanceReturns a new runtime proxy referring to the same underlying instance. It does not clone the instance.
compareinstances(a: Instance, b: Instance): booleanCompares the underlying instances behind runtime proxies.
gethui(): InstanceReturns a cloned proxy to the runtime-created HUI folder under CoreGui. This does not establish that an interface is undetectable.
Drawing.new(kind: string): DrawingObjectCreates a GUI-backed drawing object. Implemented kinds: Line, Text, Circle, Square, Image, Quad and Triangle. Shared fields include Visible, ZIndex, Transparency and Color; objects expose Remove and Destroy. Transparency 1 is opaque and 0 is transparent.
local label = Drawing.new("Text")
label.Text = "Cobalt"
label.Position = Vector2.new(40, 40)
label.Size = 18
label.Color = Color3.new(1, 1, 1)
label.Visible = true
-- label:Remove()isrenderobj(object: any): booleanChecks whether the object exposes the runtime’s Drawing Object marker.
getrenderproperty(object: DrawingObject, property: string): anyReads a property after checking isrenderobj.
setrenderproperty(object: DrawingObject, property: string, value: any)Writes a property after checking isrenderobj.
cleardrawcache()Clears all children of the runtime’s drawing GUI.
setclipboard(content: any)Converts a non-nil value to a string and sends it to the desktop clipboard. Empty strings are ignored.
Aliases: toclipboard, setrbxclipboard
isrbxactive(): booleanReturns the runtime’s Roblox focus flag, updated by WindowFocused and WindowFocusReleased events.
Aliases: isgameactive, iswindowactive
setfpscap(cap: number)Writes UserSettings().GameSettings.FramerateCap. Values at or below zero are converted to math.huge; actual acceptance depends on the client.
getfpscap(): numberReads UserSettings().GameSettings.FramerateCap.
getsenv(script: Instance): tableReturns only {script = script}. It does not retrieve the script’s actual environment.
Compatibility stub
setreadonly(value: table): tableReturns table.clone(value). It does not change the original table’s read-only state; a second boolean argument is not used.
Compatibility behavior
isreadonly(value: table): booleanReturns table.isfrozen(value).
hookfunction(original: function, replacement: function): function?Scans the caller environment, then the executor environment, replacing the first matching direct value. Returns the replacement when found, otherwise nil. It does not globally patch a function or return its original closure.
Aliases: replaceclosure
Limited environment replacement
getthreadcontext(): numberReturns a local compatibility variable, initially 3. This is not a verified read of native thread identity.
Aliases: getthreadidentity, getidentity
setthreadidentity(value: number)Only changes the local variable returned by getthreadcontext. It does not perform a native privilege change.
Aliases: setidentity, setthreadcontext
debug.getinfo(functionOrLevel: function | number, options: string?): tableBuilds a table from debug.info. Defaults to flnSu. Supports S, f, l, n, u and a; nups is reported as -1 rather than an actual upvalue count.
debug.getconstant(fn: function, index: number): anyIndexes a fixed placeholder array containing "print" and "Hello, world!". It does not inspect fn.
Placeholder
debug.getconstants(fn: function): tableReturns fixed example constants rather than the supplied function’s constants.
Placeholder
debug.getstack(level: number, index: number?): anyReturns "ab" when index is supplied, otherwise {"ab"}. It does not inspect stack values.
Placeholder
debug.getprotos(...): tableReturns a synthetic callable table whose indexed functions return true. It does not enumerate function prototypes.
Aliases: debug.getproto
Placeholder
debug.getupvalue(...)Returns nil without inspecting an upvalue.
Not implemented
debug.setconstant(...)Returns nil without changing constants.
Not implemented
debug.setstack(...)Returns nil without changing stack values.
Not implemented
debug.setupvalue(...)Returns nil without changing upvalues.
Not implemented
No matching functions.
| Action | Shortcut |
|---|---|
| New tab | Ctrl + N |
| Import file | Ctrl + O |
| Save active file | Ctrl + S |
| Save As / Export | Ctrl + Shift + S |
| Execute active script | Ctrl + Enter |
| Toggle explorer | Ctrl + B |
| Toggle output panel | Ctrl + ` |
| Move focused tab | Ctrl + Shift + ← / → |