RbxUtil Documentation
repository·main·Indexed 19 days ago
https://github.com/sleitnick/rbxutilA comprehensive suite of utility libraries for Roblox developers. RbxUtil provides specialized modules for networking (Net, Comm, TypedRemote), data manipulation (BufferUtil, Ser, TableUtil), physics (PID, Spring, Quaternion), and lifecycle management (Trove). The libraries are available via Wally and npm (@rbxutil) and are compatible with Rojo and roblox-ts.
What's inside RbxUtil
- RbxUtil is a collection of specialized utility modules for Roblox development. Each module addresses a specific technical need, ranging from networking and buffer manipulation to physics (springs/PID) and object lifecycle management (Trove).
Configure TypeScript types for @rbxutil
mainTo enable type checking and autocompletion for
@rbxutilmodules, add the@rbxutildirectory to thetypeRootsarray in yourtsconfig.jsonfile. The@rbxtsdirectory should also be present in this list."typeRoots": ["node_modules/@rbxts", "node_modules/@rbxutil"]Sync Wally packages into Roblox Studio using Rojo
mainAfter installing dependencies with Wally, you must configure Rojo to sync the
Packagesfolder into your Roblox DataModel (typicallyReplicatedStorage). Add a mapping for thePackagesdirectory in yourdefault.project.jsonfile.{ "name": "rbx-util-example", "tree": { "$className": "DataModel", "ReplicatedStorage": { "$className": "ReplicatedStorage", "Packages": { "$path": "Packages" } } } }Install @rbxutil modules via npm
mainRbxUtil modules are published under the
@rbxutilNPM organization and can be installed like any otherroblox-tspackage. To install a specific library, such as the quaternion library, usenpm installwith the package name prefixed by@rbxutil.$ npm install @rbxutil/quaternionInstall RbxUtil modules via Wally
mainRbxUtil modules are distributed via Wally, a package manager for Roblox.
- Run
wally initin your project directory to initialize awally.tomlfile. - Add the desired utility modules to your
[dependencies]section inwally.toml. - Run
wally installto download the dependencies into aPackagesfolder.
[package] name = "your_name/your_project" version = "0.1.0" registry = "https://github.com/UpliftGames/wally-index" realm = "shared" [dependencies] Signal = "sleitnick/signal@^1" TableUtil = "sleitnick/table-util@^1"- Run
Configure Rojo for @rbxutil modules
mainTo ensure that
@rbxutilmodules are correctly included in your Roblox project, you must add the@rbxutildirectory to yourdefault.project.jsonfile. It is recommended to place it inReplicatedStoragealongside the@rbxtsdirectory."node_modules": { "$className": "Folder", "@rbxts": { "$path": "node_modules/@rbxts" }, "@rbxutil": { "$path": "node_modules/@rbxutil" } }How Sequents work
mainA
Sequentis a signal-like structure that executes connected callbacks in a serial manner. Unlike standard signals where all callbacks run concurrently or independently, each connection in aSequentmust fully complete before the next one begins.Key characteristics:
- Serial Execution: Connections are run one after another.
- Prioritization: Connections can be assigned a priority to control the order of execution.
- Cancellable Events: If a
Sequentis created withcancellableset totrue, a callback can callevent:Cancel()to prevent the event from propagating to any subsequent connections in the sequence. - Yielding: The
Firemethod yields until all connections have completed.
local sequent = Sequent.new(true) -- true enables event cancellation sequent:Connect(function(event) print("First connection") event:Cancel() -- Stops subsequent connections from running end, Sequent.Priority.Highest) sequent:Connect(function(event) print("This won't print!") end, Sequent.Priority.Lowest) sequent:Fire("Test")Create procedural shake effects with Shake
mainThe
Shakemodule allows you to create realistic procedural shake effects for cameras or objects.To use it:
- Create a new instance with
Shake.new(). - Configure properties like
Amplitude,Frequency, andFadeInTime. - Call
shake:Start(). - Bind the shake to a loop using
shake:OnSignal(signal, callback)orshake:BindToRenderStep(name, priority, callback).
Shakes automatically stop and clean up their connections once they complete. If you need to run multiple shakes with the same configuration simultaneously, use
shake:Clone()to create a new instance from a preset.Note:
shake:Start()must be called beforeUpdate,OnSignal, orBindToRenderStep.local priority = Enum.RenderPriority.Last.Value local shake = Shake.new() shake.FadeInTime = 0 shake.Frequency = 0.1 shake.Amplitude = 5 shake.RotationInfluence = Vector3.new(0.1, 0.1, 0.1) shake:Start() shake:BindToRenderStep(Shake.NextRenderName(), priority, function(pos, rot, isDone) camera.CFrame *= CFrame.new(pos) * CFrame.Angles(rot.X, rot.Y, rot.Z) end)- Create a new instance with
Create a Stream
mainYou can initialize a
Streamusing several methods depending on your source data:stream.create(size): Creates a new stream with a fresh buffer of the specifiedsizein bytes.stream.frombuffer(buf): Wraps an existingbufferin a stream.stream.fromstring(str): Converts a string into a buffer and wraps it in a stream.
local s = stream.create(4) local s_from_buf = stream.frombuffer(existing_buffer) local s_from_str = stream.fromstring("hello")Create a new Signal
mainUse
Signal.new()to create a fresh Signal instance for event-driven programming. This implementation is batched and yield-safe, meaning handlers can yield without significant performance overhead.local signal = Signal.new() -- Subscribe to a signal: signal:Connect(function(msg) print("Got message:", msg) end) -- Dispatch an event: signal:Fire("Hello world!")Use RbxUtil modules in Luau scripts
mainTo use the installed modules, reference the
Packagesfolder (usually located inReplicatedStorage) and userequire()on the specific module.Example workflow:
- Locate the
Packagesfolder inReplicatedStorage. requirethe module.- Call the module's API methods.
-- Reference folder with packages: local Packages = game:GetService("ReplicatedStorage").Packages -- Require the utility modules: local Signal = require(Packages.Signal) local TableUtil = require(Packages.TableUtil) -- Use the modules: local signal = Signal.new() signal:Connect(function(data) local randomizedData = TableUtil.Shuffle(data) print(randomizedData) end) signal:Fire({"A", "B", "C"})- Locate the
Configure Shake properties
mainUse the following properties to customize the behavior of a
Shakeinstance:Amplitude(number): The overall magnitude of the shake. Defaults to1.Frequency(number): The speed of the shake. Defaults to1.FadeInTime(number): Duration in seconds to fade in to max amplitude. Defaults to1.FadeOutTime(number): Duration in seconds to fade out after sustain/completion. Defaults to1.SustainTime(number): How long the shake stays at full amplitude before fading out. Defaults to0.Sustain(boolean): Iftrue, the shake lasts indefinitely untilshake:StopSustain()is called. Defaults tofalse.PositionInfluence(Vector3): Multiplier for the position offset vector. Defaults toVector3.one.RotationInfluence(Vector3): Multiplier for the rotation offset vector. Defaults toVector3.one.TimeFunction(function): A function returning the current time (defaults totimeoros.clock).