utility

The `utility` library contains general-purpose helper functions for tasks like math, logging, and time.

utility.RandomInt(min, max)

Returns a random integer between min and max (inclusive).

utility.RandomFloat(min, max)

Returns a random floating-point number between min and max.

utility.GetTickCount()

Returns the number of milliseconds that have elapsed since the system was started.

Returns:

  • number

utility.GetDeltaTime()

Returns the time in seconds it took to complete the last frame. Useful for framerate-independent animations.

Returns:

  • number

utility.WorldToScreen(Vector3: object)

Converts a Vector3 object of coordinates into a 2D screen coordinate.

Returns:

  • screenX: number - The X coordinate on the screen.

  • screenY: number - The Y coordinate on the screen.

  • onScreen: boolean - true if the point is within the visible screen area.


local part = game.Workspace.MyPart
local part_position_vector = part.Position -- This is a Vector3 object

local sx, sy, is_on_screen = utility.world_to_screen(part_position_vector)

if is_on_screen then
    draw.text("Here!", sx, sy, Color3.new(1, 1, 1))
end

LoadImage

Loads raw image data (e.g., from a .png or .jpg file) into a GPU texture and returns a handle to it. This handle is then used by draw.Image.

  • Aliases: utility.LoadImage, utility.loadImage, utility.load_image

  • Signature: utility.LoadImage(image_data)

  • Parameters:

    • image_data: string - The raw binary content of an image file, typically read using file.read().

  • Returns: integer - A unique texture ID to be used with draw.Image. Returns nil or throws an error on failure.

  • Example:

    Generated lua

    local image_data = file.read("my_logo.png")
    if image_data then
        local logo_texture_id = utility.load_image(image_data)
        
        if logo_texture_id then
            cheat.register("onPaint", function()
                draw.image(logo_texture_id, 50, 50, 100, 100, 255, 255, 255, 255)
            end)
        end
    end

Last updated