Versa | A versatile module with 19 different submodules!

Versa is a module I’ve been working on for a bit, with MANY utility features.

This may not be a complete documentation.

Get it here!

Documentation

Expand

Overview

The “Versa” module is a collection of utility functions.

Usage

To use the Versa module in your game, you need to require it first. Assuming the module script is named “Versa”, use the following code:

local versa = require(path.to.Versa) -- Adjust the path accordingly

Storage

The Storage feature provides a simple way to manage and store objects in a table.

Functions

Place(self, name: string, object: any)

Places an object into the storage table with the given name. If an object with the same name already exists, it will throw an error.

  • self: The storage table.
  • name: The name of the object to store.
  • object: The object to store.
versa.Storage:Place("sword", game.ServerStorage.SwordModel)

Retrieve(self, name: string)

Retrieves the object with the given name from the storage table. If the object does not exist, it will throw an error.

  • self: The storage table.
  • name: The name of the object to retrieve.
local sword = versa.Storage:Retrieve("sword")

Remove(self, name: string)

Removes the object with the given name from the storage table and returns it. If the object does not exist, it will throw an error.

  • self: The storage table.
  • name: The name of the object to remove.
local sword = versa.Storage:Remove("sword")

Part

The Part feature provides a function to manipulate a part’s position and size.

Function

TracePart(part: Instance, p0: Vector3, p1: Vector3, width: number, height: number)

Traces a part from point p0 to point p1, sets its position and size accordingly.

  • part: The part to manipulate.
  • p0: The starting point of the trace (Vector3).
  • p1: The ending point of the trace (Vector3).
  • width: The width of the part.
  • height: The height of the part.
local part = Instance.new("Part")
part.Size = Vector3.new(1, 1, 1)

versa.Part:TracePart(part, Vector3.new(0, 0, 0), Vector3.new(5, 0, 5), 2, 3)

Math

The Math feature provides various mathematical functions.

Functions

Lerp(a: number, b: number, t: number)

Linearly interpolates between a and b based on t.

  • a: The starting value.
  • b: The ending value.
  • t: The interpolation value (should be between 0 and 1).
local result = versa.Math:Lerp(10, 20, 0.5) -- Returns 15

Flip(num: number)

Flips the sign of the given number.

  • num: The number to flip.
local result = versa.Math:Flip(5) -- Returns -5

Largest(array: table, place: number)

Finds the place-th largest element in the given array.

  • array: The input table (should contain numbers).
  • place: The position of the largest element to find.
local numbers = {3, 1, 5, 2, 4}
local result = versa.Math:Largest(numbers, 2) -- Returns 4 (2nd largest element)

HasDecimal(num: number)

Checks if a number has a decimal component.

  • num: The number to check.
local result = versa.Math:HasDecimal(3.14) -- Returns true

Constants

Epsilon

A very small number used for floating-point comparison.

print(versa.Math.Epsilon) -- Outputs 2.2204460492503e-16

Euler

The Euler’s number (approximately 2.718281828459).

print(versa.Math.Euler) -- Outputs 2.718281828459

GoldenRatio

The golden ratio (approximately 1.6180339887499).

print(versa.Math.GoldenRatio) -- Outputs 1.6180339887499

Instance

The Instance feature provides a function to create new instances with properties.

Function

new(class: string, parent: Instance, properties: table)

Creates a new instance of the given class and sets its properties.

  • class: The class of the instance to create (e.g., “Part”, “Folder”).
  • parent: The parent of the new instance.
  • properties: A table containing properties to set on the new instance.
local part = versa.Instance.new("Part", workspace, {
    Size = Vector3.new(2, 2, 2),
    Color = Color3.new(1, 0, 0),
    Anchored = true,
})

Sandbox

The Sandbox feature allows you to run and manage coroutines within isolated sandboxes.

Functions

Run(name: string, funct: any)

Runs the provided function in a sandbox with the given name.

  • name: The name of the sandbox.
  • funct: The function to run within the sandbox.
versa.Sandbox:Run("mySandbox", function()
    print("This code runs in a sandbox!")
end)

Yield(name: string)

Pauses the execution of the specified sandbox.

  • name: The name of the sandbox to yield.
versa.Sandbox:Yield("mySandbox")

Resume(name: string)

Resumes the execution of the specified sandbox.

  • name: The name of the sandbox to resume.
versa.Sandbox:Resume("mySandbox")

Random

The Random feature provides a way to generate random numbers.

Function

new(seed: number)

Creates a new random number generator object with the given seed.

  • seed: The seed for the random number generator.
local random = versa.Random:new(123)

Methods

Number(n: number, m: number)

Generates a random floating-point number between n and m.

  • n: The lower bound of the range.
  • m: The upper bound of the range.
local random = versa.Random:new(123)
local result = random:Number(0, 1) -- Returns a random number between 0 and 1

`Integer(n: number,

m: number)`

Generates a random integer between n and m.

  • n: The lower bound of the range.
  • m: The upper bound of the range.
local random = versa.Random:new(123)
local result = random:Integer(1, 10) -- Returns a random integer between 1 and 10

Table(table: table)

Returns a random element from the provided table.

  • table: The table from which to select a random element.
local random = versa.Random:new(123)
local fruits = {"apple", "banana", "cherry"}
local fruit = random:Table(fruits) -- Returns a random fruit

Boolean()

Returns a random boolean value (true or false).

local random = versa.Random:new(123)
local result = random:Boolean() -- Returns a random boolean

Asset

The Asset feature provides a function to load assets from the Roblox asset library.

Function

Load(assetId: number)

Loads the asset with the given ID from the Roblox asset library. If it fails to load the asset, it will print a warning and return nil.

  • assetId: The ID of the asset to load.
local model = versa.Asset:Load(1818) -- Loads the "Classic Sword" model

Pool

The Pool feature provides a simple event system.

Functions

Listen(recipient: string, channel: string, funct: any)

Listens for events on the given channel. When an event is emitted on that channel, it calls the provided function.

  • recipient: The recipient of the event.
  • channel: The channel to listen to.
  • funct: The function to call when an event is emitted on the channel.
versa.Pool:Listen("myRecipient", "myChannel", function(data)
    print("Received event with data: ", data)
end)

Emit(channel: string, data: any)

Emits an event on the given channel with the provided data.

  • channel: The channel to emit the event on.
  • data: The data to send with the event.
versa.Pool:Emit("myChannel", "Hello, world!")

Disconnect(recipient: string, channel: string)

Stops listening for events on the given channel for the specified recipient.

  • recipient: The recipient to disconnect.
  • channel: The channel to stop listening to.
versa.Pool:Disconnect("myRecipient", "myChannel")

Cross

The Cross feature provides a way to publish and listen to messages across different servers or places in a game using the Roblox MessagingService.

Functions

Publish(channel: string, data: any)

Publishes a message on the given channel with the provided data.

  • channel: The channel to publish the message on.
  • data: The data to send with the message.
versa.Cross:Publish("myChannel", "Hello, world!")

Listen(channel: string, funct: any)

Listens for messages on the given channel. When a message is published on that channel, it calls the provided function.

  • channel: The channel to listen to.
  • funct: The function to call when a message is published on the channel.
versa.Cross:Listen("myChannel", function(message)
    print("Received message: ", message)
end)

Debounce

The Debounce feature provides a way to limit the frequency of function calls.

Function

new(delayTime: number)

Creates a new debounce object that allows a function to be called after the specified delay time.

  • delayTime: The minimum delay time (in seconds) between function calls.
local debounce = versa.Debounce.new(0.5)

Method

Pass()

Checks if the minimum delay time has passed since the last function call. If it has, it allows the function to be called and returns true. If not, it prevents the function from being called and returns false.

if debounce:Pass() then
    print("This will not be printed more often than every 0.5 seconds")
end

Schedule

The Schedule feature provides a way to schedule a function to be called after a delay.

Function

Schedule(funct: any, delayTime: number)

Schedules the provided function to be called after the specified delay time.

  • funct: The function to schedule.
  • delayTime: The delay time (in seconds) before the function is called.
local schedule = versa.Schedule(function()
    print("This will be printed after 5 seconds")
end, 5)

Methods

Do()

Immediately calls the scheduled function, if it has not been called yet.

schedule:Do()

Cancel()

Cancels the scheduled function, preventing it from being called.

schedule:Cancel()

Fun

The Fun feature provides various fun and miscellaneous functions.

Function

Please(funct: any)

Calls the provided function with a 50% chance. Returns true if the function was called, and false otherwise.

  • funct: The function to possibly call.
local result, message = versa.Fun.Please(function()
    print("This may or may not be printed")
end)
print(result, message) -- Outputs either "true, Sure, why not?" or "false, I don't feel like it."

Text

The Text feature provides various text-related functions.

Zalgo(text: string)

Transforms the provided text into “Zalgo” text, which is text with added combining diacritical marks.

  • text: The text to transform.
local zalgoText = versa.Fun.Text:Zalgo("Hello, world!")
print(zalgoText) -- Outputs "H̕͜͠ę̶͡l͢͏̕l̛̕ơ͠,͞ ͡w̵̵͞o͡r̸̡l͡͏d̸̕͏!̶̕͞"

Players

The Players feature provides functions for manipulating and managing players.

Function

Hook(player: Instance)

Hooks into the provided player, providing a convenient way to manipulate the player and their leaderstats.

  • player: The player to hook into.
local hookedPlayer = versa.Players:Hook(game.Players.Player1)

Methods

Disconnect.Abrupt()

Disconnects the hooked player from the game without any feedback to the player.

hookedPlayer.Disconnect:Abrupt()

Disconnect.Kick(reason: string)

Disconnects the hooked player from the game with the provided reason.

  • reason: The reason for the kick.
hookedPlayer.Disconnect:Kick("You have been kicked from the game.")

`Team

.Set(teamName: string)`

Sets the hooked player’s team to the specified team.

  • teamName: The name of the team to set.
hookedPlayer.Team:Set("Red Team")

Leaderstats[index: string]

Gets or sets the hooked player’s leaderstat with the specified index.

  • index: The index of the leaderstat.
hookedPlayer.Leaderstats["Points"] = 100 -- Sets the "Points" leaderstat to 100
local points = hookedPlayer.Leaderstats["Points"] -- Gets the "Points" leaderstat

AddFunction(callback: any)

Adds a function that is called whenever a player joins the game. The function is also called for all players currently in the game.

  • callback: The function to call.
local function = versa.Players:AddFunction(function(player)
    print(player.Name .. " has joined the game")
end)

Method

Disconnect()

Disconnects the function from the PlayerAdded event, preventing it from being called when a player joins the game.

function:Disconnect()

Throttling

The Throttling feature provides a way to limit the rate of function calls.

Function

new(timeFrame: number, maxCalls: number)

Creates a new throttling object that limits the number of function calls within a certain time frame.

  • timeFrame: The time frame (in seconds) for the throttling.
  • maxCalls: The maximum number of function calls allowed within the time frame.
local throttling = versa.Throttling.new(1, 5) -- Allows a maximum of 5 function calls per second

Method

Pass()

Checks if the maximum number of function calls has been reached within the time frame. If it has, it prevents the function from being called and returns false. If not, it allows the function to be called and returns true.

if throttling:Pass() then
    print("This will not be printed more than 5 times per second")
end

Timer

The Timer feature provides a simple timer with customizable tick intervals.

Function

new(time: number, tickInterval: number)

Creates a new timer that counts down from the specified time and ticks at the specified intervals.

  • time: The time (in seconds) for the timer to count down from.
  • tickInterval: The interval (in seconds) at which the timer ticks.
local timer = versa.Timer.new(10, 1) -- Creates a timer that counts down from 10 seconds and ticks every 1 second

Methods

Start()

Starts the timer. When the timer ticks, it calls the Tick function with the remaining time as a parameter. When the timer ends, it calls the Ended function.

timer.Tick = function(timeLeft)
    print("Time left: ", timeLeft)
end
timer.Ended = function()
    print("Timer ended")
end
timer:Start()

Cancel()

Cancels the timer, preventing the Tick and Ended functions from being called.

timer:Cancel()

Array

The Array feature provides various array-related functions.

Functions

Limit(array: table, lowerBound: number, upperBound: number)

Returns a new array containing only the elements of the original array that are within the specified bounds.

  • array: The original array.
  • lowerBound: The lower bound.
  • upperBound: The upper bound.
local array = {1, 2, 3, 4, 5}
local limitedArray = versa.Array:Limit(array, 2, 4) -- Returns {2, 3, 4}

ForEach(array: table, callback: any)

Calls the provided function for each element in the array.

  • array: The array.
  • callback: The function to call.
local array = {"apple", "banana", "cherry"}
versa.Array:ForEach(array, function(element)
    print(element)
end)

Misc

The Misc feature provides various miscellaneous functions.

Base64

The Base64 feature provides functions for encoding and decoding Base64.

Encode(data)

Encodes the provided data into Base64.

  • data: The data to encode.
local base64 = versa.Misc.Base64:Encode("Hello, world!")
print(base64) -- Outputs "SGVsbG8sIHdvcmxkIQ=="

Decode(data)

Decodes the provided Base64 into data.

  • data: The Base64 to decode.
local data = versa.Misc.Base64:Decode("SGVsbG8sIHdvcmxkIQ==")
print(data) -- Outputs "Hello, world!"

DataStore

The DataStore feature provides a convenient way to interact with the Roblox Data Store.

Function

GetStore(storeName: string)

Gets the Data Store with the specified name.

  • storeName: The name of the Data Store.
local store = versa.DataStore:GetStore("MyStore")

Methods

Get(key: string, value: any)

Gets the value associated with the specified key in the Data Store.

  • key: The key.
local value = store:Get("MyKey")
print(value) -- Outputs the value associated with "MyKey", or nil if no value is associated

Set(key: string, value: any)

Sets the value associated with the specified key in the Data Store.

  • key: The key.
  • value: The value to associate with the key.
store:Set("MyKey", "MyValue")

Loadstring

The Loadstring feature provides a safe and secure way to evaluate strings of Lua code.

Function

Loadstring(str: string, env: table)

Evaluates the provided string of Lua code in a secure environment.

  • str: The string of Lua code to evaluate.
  • env: An optional table specifying the environment in which to evaluate the code.
local result = versa.Loadstring("return 2 + 2") -- Returns 4
2 Likes

this is just renaming already existing things, what’s the point in using it?

3 Likes

i still wanna add new stuff … :smiling_face_with_tear:

1 Like

its also my first public resource, and i intended to make it SIMPLIFY already existing things