getNearestObject

Finds the nearest object within the specified distance.

Parameters:

  • coords (vector3, optional): The coordinates to search from. Defaults to player's current position.

  • distance (number, optional): Maximum search distance in units. Defaults to 10.0.

Returns:

  • object (entity): The nearest object entity, or 'no nearby object' if none found

  • distance (number): Distance to the nearest object, or 'no nearby object' if none found

Example:

local nearestObject, objectDistance = ps.getNearestObject()
if nearestObject ~= 'no nearby object' then
    local model = GetEntityModel(nearestObject)
    print("Found object model: " .. model)
end

Last updated