Skip to content

Utility

Utility is a highly useful library packed with frequent development functions, with its main goal being to speed up development.


Variables

  • States: table used to cache states
  • StateActions: table used to cache state actions
  • RaycastParams: RaycastParams used internally during raycasts
  • HumanoidDescriptionCache: table used to cache HumanoidDescriptions (SERVER)

Functions

State(State | string, Value: false)

Returns a function to change the specified state's value. Creates the state using the specified value if state didn't previously exist.

local TestState = Utility:State("TestState")

TestState(not Utility.States.TestState)

StateAction(State | string, Item | Instance, Value, Duration | number: 0.5, ...)

Creates an action that affects the specified item whenever the set value is assigned to the specified state.

local LowGravity = Utility:State("LowGravity")

Utility:StateAction("LowGravity", workspace, true, 0.5, "Gravity", 32)
Utility:StateAction("LowGravity", workspace, false, 0.5, "Gravity", 196.2)

LowGravity(true)

DotAngle(Vec1 | Vector3, Vec2 | Vector3, SubVec1 | Vector3: Vec1)

Returns the angle between Vec1 and Vec2 in degrees.

IsFacing(Origin | CFrame, Target | Vector3, Limit | number: 40)

Returns whether or not the origin is facing the target position. Limit is an angle in degrees.

local Facing, Angle = Utility:IsFacing(Origin, Target)

MouseXY(Camera | Camera) (CLIENT)

Returns the x and y angles of the camera's orientation relative to the world facing front in radians. x goes from -π to π and y goes from -π/2 to π/2.

Ray(Origin | Vector3, Target | Vector3, Length | number: 250)

Generates and returns a Ray based on the given parameters.

CastRay(Origin | Vector3, Target | Vector3, Length | number, Ignore | table: { }, IgnoreWater | bool: false)

Returns the result of a raycast done through the given parameters. If Length is false, the cast will not perform a (Target - Origin) subtraction, expecting Target to be the Direction instead.

local Result = Utility:CastRay({ -- Dictionary format is optional
    Origin = Vector3.new(0, 0, 0),
    Target = Vector3.new(0, 10, 0),
    Length = 10
})

print(Result)

Beam(Part | BasePart: nil, Origin | Vector3, Target | Vector3, Size | bool: true, Anchor | bool: nil, XYSize | number: 0.1, YZSize | number: 0.1)

Returns a part positioned and rotated between Origin and Target. If no part is given through the Part paremeter, a new part will be generated.

local Part, Length = Utility:Beam({ -- Dictionary format is optional
    Origin = Vector3.new(0, 0, 0),
    Target = Vector3.new(10, 0, 5),
    Anchor = true
})

SpinTo(Origin | CFrame, Target | Vector3)

Returns a transformed CFrame that makes the Origin face the Target position with a Y axis rotation.

Shade(Color | Color3, Amount | number/Color3: 155)

Returns the subtraction of the specified color by the specified amount.

Lerp(A | number, B | number, T | number)

Returns the numerical lerp of A to B by T.

WaitForChild(Parent | Instance, Child | string, Timeout | number: math.huge)

Returns the child as soon as it exists in the given parent, with an optional timeout.
This is preferred over using :WaitForChild() in situations where the instance may not already be available, as this function's approach is much faster depending on the server's performance.

Character(Player | Player, Default | bool: true, Spawn | bool: true, Specifics | table: { Head = 0, Torso = 0, ... }, Blacklist | table: { }) (SERVER)

Loads and returns a HumanoidDescription for the specified player. This is useful for disabling packages, defining default character parts and blacklisting character assets.

local HumanoidDescription = Utility:Character(Player, true, true, { -- Specifics (Define the description)
    ClimbAnimation = 0,
    FallAnimation = 0,
    IdleAnimation = 0,
    JumpAnimation = 0,
    RunAnimation = 0,
    SwimAnimation = 0,
    WalkAnimation = 0,
    BodyTypeScale = 0,
    HeadScale = 1,
    HeightScale = 1,
    ProportionScale = 0,
    WidthScale = 1
}, { -- Blacklist (Disallow certain items)
    ["MetatableIndex"] = { 134082579 },
    Head = 2608540431,
    Torso = 2608539495,
    RightLeg = 2608538559,
    LeftLeg = 2608536258,
    RightArm = 2608537440,
    LeftArm = 2608534881
})

HumanoidDescription:Destroy()

Teleport(Id | number, Server | string, Player | Player, ...)

Teleports the player to the specified place id. Server is optional. The Player parameter does not exist in the client.

Characters(IncludeDead)

Returns all the characters on the map.

Closest(Position | Vector3, List | table: Utility:Characters())

Returns the closest part to the specified position. If a model is found in the table, only the PrimaryPart will be checked.

ClosestVisible(Position | Vector3, List | table: Utility:Characters(), Ignore | table: table.clone(List), MaxDistance | number: math.huge, ReturnAnyways | bool: false)

Returns the closest visible part to the specified position. If a model is found in the table, only the PrimaryPart will be checked. If ReturnAnyways is set to true, the closest non-visible part will be returned if no part is visible.

local Closest, Distance, Visible = Utility:ClosestVisible({ -- Dictionary format is optional
    Position = script.Parent.HumanoidRootPart.Position,
    ReturnAnyways = true -- Optional (bool)
})

LightRadius(Light | Light)

Returns an approximate of the specified light's visible circular radius.

Back to top