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.GetFingerprint()

Returns a unique hardware identifier (fingerprint) for the current user.

utility.SetClipboard(string: content)

Sets the system clipboard to the specified text content.

utility.SetClipboard("This text is now in the clipboard!")

utility.GetClipboard()

Returns the current text content from the system clipboard as a string.

utility.MoveMouse(integer: dx, integer: dy)

Moves the mouse cursor relative to its current position.

  • dx: The number of pixels to move horizontally (positive is right, negative is left).

  • dy: The number of pixels to move vertically (positive is down, negative is up).

-- Move the mouse 50 pixels to the right and 20 pixels up
utility.MoveMouse(50, -20)

utility.GetDeltaTime()

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

Returns:

  • number

utility.GetMousePos()

Returns the mouse position.

Returns:

  • vector2 table

utility.GetMenuState()

Returns the menu state.

Returns:

  • boolean

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