writecustomasset Synchronous

Write bytes to a workspace file and get an asset URI for it in one step. Use it for an image or sound your script has just generated or downloaded.

Syntax
Luau
writecustomasset(path: string, contents: string) -> string

Parameters

Function parameters
ParameterTypeDescription
pathstringWorkspace-relative path to write, including the file extension.
contentsstringFile bytes, such as PNG or MP3 data.

Returns

string

An asset URI, the same as getcustomasset returns for that file.

Usage notes

Existing contents at the path are replaced. The file stays in the workspace afterwards, as if you had called writefile and then getcustomasset.

Example

Example
Luau
local image = game:HttpGet("https://example.com/icon.png")
local decal = Instance.new("Decal")
decal.Texture = writecustomasset("assets/icon.png", image)