Util
Install with wally by adding the following to your wally.toml
:
Util = "dig1t/util@1.0.19"
Types
ValueBaseType
This is a custom type to represent and typecheck value instances.
Roblox has a built-in ValueBase type, but it does not have a Value
property.
Example:
local value: ValueBaseType = Instance.new("BoolValue")
Properties
userLevel
Util.userLevel:
table
<
number,
number
>
Functions
getPartCount
Gets the number of parts in the given instance
Example:
Util.getPartCount(game.Workspace.NPC) -- 5
getDescendantParts
Gets all parts in the given instance
Example:
Util.getDescendantParts(game.Workspace.LightPost) -- { [1] = Light, [2] = PostMeshPart }
getAncestor
Gets the first descendant of the given instance that matches the given condition. This will search all descendants of the given instance, including the instance itself. It will stop if no ancestor is found.
Example 1:
detector.Touched:Connect(function(part: BasePart)
local humanoid = Util.getAncestor(part, "Humanoid")
if humanoid ~= nil then
print("Humanoid touched the detector")
end
end)
Example 2:
detector.Touched:Connect(function(part: BasePart)
local bot: Model? = Util.getAncestor(part, function(instance: Instance)
return instance:HasTag("NPC")
end)
if bot ~= nil then
bot.
print("NPC bot touched the detector")
end
end)
find
Util.
find
(
maxDepth:
number
,
--
Default: 1
_depth:
number
--
Internal use, used to track the current depth
) →
any
Starts at the given node and searches all children for the first child that matches the given condition.
This search will continue until maxDepth
is reached, a match is found, or no more children are found.
When a match is found, it will return the matching child.
When no match is found, it will return nil.
By default maxDepth
is 1. Only the children of the given node will be searched.
Function condition example:
local player: Player? = Util.find(game.Players, function(player: Player)
return player.Name == "Player1"
end)
Instance example:
local player: Player? = Util.find(game.Players, "Player1")
Filtering example:
local NPCs = {
{ Name = "NPC1" },
{ Name = "NPC1" },
{ Name = "NPC1" },
}
local player = Util.find(NPCs, function(NPC)
return NPC.Name == "NPC1"
end)
Advanced example:
local NPCs = {
{ Name = "NPC1", Health = 0 },
{ Name = "NPC1", Health = 20 },
{ Name = "NPC1", Health = 0 },
}
local firstAliveNPC = Util.find(NPCs, function(NPC)
return NPC.Health > 0
end)
exists
Checks if the given instance has the children with the given key names. A single child name can be passed as a string, or multiple child names can be passed as a table.
Table of children example:
Util.exists(
game.Workspace.Player1,
{ "Head", "Torso", "Left Arm", "Right Arm", "Left Leg", "Right Leg" }
) -- true
String child example:
Util.exists(game.Workspace.Player1, "Head") -- true
Table of children in a table node example:
Util.exists(
game.Workspace.Player1:GetChildren(), -- table
{ "Head", "Torso" }
) -- true
Table node and string child example:
Util.exists(
game.Workspace.Player1:GetChildren(), -- table
"HumanoidRootPart"
) -- true
getFirstPart
Returns the first part in the given instance
Example:
Util.getFirstPart(game.Workspace.Player1) -- Head
round
Util.
round
(
_number:
number
) →
number
Rounds a number to the nearest integer.
Example:
Util.round(1.5) -- 2
Util.round(1.4) -- 1
formatNumber
Util.
formatNumber
(
number:
number
,
decimals:
number?
--
The number of decimal places to round to. Defaults to 2.
) →
string
Formats a number to have commas.
Example:
Util.formatNumber(1000) -- 1,000
Util.formatNumber(1000.01) -- 1,000.01
random
Util.
random
(
minValue:
number
,
maxValue:
number?
,
float:
boolean?
--
Whether to return as a float or not. Defaults to false.
) →
number
Returns a random number between two numbers.
Example:
Util.random(1, 10) -- 5
Util.random(1, 10, true) -- 5.5
Util.random(10) -- 5 (min defaults to 1)
Util.random(10, true) -- 5.5 (min defaults to 1)
randomString
Util.
randomString
(
length:
number?
--
Length of the string (defaults to 18)
) →
string
Returns a random string.
Example:
Util.randomString() -- "aBcDeFgHiJkLmNoPqRsTuVwXyZ"
Util.randomString(10) -- "aBcDeFgHiJ"
randomObj
Returns a random object from a table or instance.
Example:
Util.randomObj({ "a", "b", "c" }) -- "b"
Util.randomObj(Workspace.Player) -- Head
coinFlip
Util.
coinFlip
(
) →
boolean
Returns a random boolean.
Example:
Util.coinFlip() -- true
Util.coinFlip() -- false
shortenNumber
Util.
shortenNumber
(
number:
number
|
string
,
minimumTiers:
number?
,
--
The minimum number of tiers to shorten. Defaults to 1.
decimals:
number?
--
The number of decimal places to round to. Defaults to 1.
) →
string
Shortens a large number to a readable format. Useful for displaying large numbers that don't require exact precision. Common use cases are for displaying XP, money in leaderboards, damage etc.
Example:
Util.shortenNumber(1000) -- 1K
Util.shortenNumber(1000000) -- 1M
Util.shortenNumber(1000000000) -- 1B
Util.shortenNumber(1000000000000) -- 1T
Util.shortenNumber(1000000000000000) -- 1Q
minimumTiers is useful for when you want to shorten a number but only if it's above a certain tier. For example, if you want to shorten a number but only if it's above 1,000,000, you would do:
Util.shortenNumber(1000000, 2) -- 1,000,000
A tier is the amount of commas in a number. For example, 1,000,000 has 2 tiers and 1,000 has 1 tier.
Tier list and their abbreviations:
- 1,000 = K
- 1,000,000 = M
- 1,000,000,000 = B
- 1,000,000,000,000 = T
- 1,000,000,000,000,000 = Q
getVector3
Gets a Vector3 from an object containing a Vector3 or CFrame.
Supports:
- Vector3
- CFrame
- Attachment
- BasePart
- CFrameValue
- Vector3Value
- Camera
getDistance
Gets the distance between two Vector3s.
getPartBottomSurface
Gets the bottom surface of a part.
getGroupRank
Gets the group rank of a player.
Example:
Util.getGroupRank(game.Players.LocalPlayer, 1) -- 255
isCreator
Checks if a player is the creator of the game.
Example:
Util.isCreator(game.Players.LocalPlayer) -- true
getUserLevel
Gets the user level of a player.
Example:
Util.getUserLevel(game.Players.LocalPlayer) -- 0
Util.getUserLevel(game.Players.GameDeveloper) -- 4
Util.getUserLevel(game.Players.PremiumPlayer) -- 4
Util.getUserLevel(game.Players.Creator) -- 5
getHumanoid
Gets the humanoid object from a player's character part, character model, player object, or humanoid.
Example:
Util.getHumanoid(game.Players.LocalPlayer) -- Humanoid
isAlive
Checks if a humanoid is alive. If no humanoid is found, it will return nil
Example:
Util.isAlive(game.Players.LocalPlayer) -- true
Util.isAlive(game.Workspace.Zombie) -- false
Util.isAlive(game.Workspace.Part) -- nil, but will throw a warning
hasHumanoid
Checks if an object has a humanoid.
Example:
Util.hasHumanoid(game.Players.LocalPlayer) -- true
Util.hasHumanoid(game.Workspace.Zombie) -- true
getCharacterFromInstance
Gets the character model from a BasePart.
Useful for getting the character model from a Touched event or a raycast.
Example:
local rig: Model? = Util.getCharacterFromInstance(hit.Part)
local rigPlayer: Player? = Players:GetPlayerFromCharacter(rig)
getPlayerFromInstance
Gets the player object from a BasePart.
Example:
Util.getPlayerFromInstance(game.Workspace.Part) -- Player
dateTimeComponentsToTimestamp
Util.
dateTimeComponentsToTimestamp
(
components:
DateTimeComponents
) →
number
Converts a DateTimeComponents table to a timestamp.
unix
Util.
unix
(
) →
number
Get the current unix timestamp in UTC time. This is the number of seconds since January 1, 1970.
timeAgoUnix
Util.
timeAgoUnix
(
timestamp:
number?
,
endTimestamp:
number?
--
The timestamp to compare to. Defaults to current time.
) →
number
Gets the time in seconds since now or the provided timestamp.
formatUnix
Util.
formatUnix
(
timestamp:
number
,
format:
string
,
--
The format to use.
locale:
string?
,
--
The locale to use. Defaults to en-us
.
useUTC:
boolean?
--
Whether to use UTC time. Defaults to local time.
) →
string
--
The formatted time in local time.
Converts a unix timestamp to a mm:ss
format (e.g. 00:02).
A format and locale can be provided.
Use the DateTime API for formatting options.
Example
local secondsLeft: number = 80
Util.formatUnix(secondsLeft, "mm:ss", nil, true) -- 01:20
Util.formatUnix(secondsLeft, "HH:mm:ss", nil, true) -- 00:01:20
elapsedTimeClockFormat
Util.
elapsedTimeClockFormat
(
timestamp:
number
) →
string
--
The formatted time in local time.
Converts a unix timestamp to a mm:ss
format (e.g. 00:02).
Example
Util.elapsedTimeClockFormat(80) -- 01:20
Util.elapsedTimeClockFormat(3661) -- 01:01:01
timeAgo
Util.
timeAgo
(
timestamp:
number
,
endTimestamp:
number?
--
The timestamp to compare to. Defaults to current time.
) →
string
Converts a unix timestamp to a readable time ago format (e.g. 1 minute ago, 1 minute 20 seconds ago).
Example
local secondsLeft: number = 80
Util.timeAgo(secondsLeft) -- 1 minute ago
local secondsLeft: number = 80
Util.timeAgo(secondsLeft, 80 + 60) -- just now
totalTime
Util.
totalTime
(
timestamp:
number
,
endTimestamp:
number?
,
--
The timestamp to compare to. Defaults to current time.
separator:
string?
,
--
The separator to use between each unit. Defaults to a space.
depth:
number?
--
The maximum number of units to return.
) →
string
Similar to Util.timeAgo
but returns a more detailed string with the total time instead of the largest unit.
Convert a unix timestamp to a readable format (1 days, 1 hours, 1 minutes, 1 seconds).
Example
local secondsLeft: number = 80
Util.totalTime(secondsLeft) -- 1 minute 20 seconds
use
Injects a module into the Util module.
Example:
-- Before
Util.requiredFunction() -- error: "Function not found"
-- After
local pathToModule: ModuleScript = script.Parent.Module
Util.use(pathToModule)
Util.requiredFunction() -- "Hello world!"
printTable
Util.
printTable
(
source:
{
[
any
]
:
any
}
) →
(
)
Prints a JSON string to the console using HttpService.
Example:
Util.printTable({
foo = "bar";
bar = "foo";
}) -- {"foo":"bar","bar":"foo"}
numberSequence
Create a new NumberSequence from a table of keypoints.
Example:
local gradient: ColorSequence = Util.colorSequence({
{ 0, Color3.fromRGB(255, 0, 0) };
{ 1, Color3.fromRGB(0, 255, 0) };
})
local particle: ParticleEmitter = Instance.new("ParticleEmitter")
particle.Color = gradient
getProductInfo
Util.
getProductInfo
(
productId:
number
,
infoType:
Enum.InfoType?
) →
{
[
any
]
:
any
}
?
Retrieves product info with the Roblox marketplace API.
getAssetURI
Util.
getAssetURI
(
assetId:
(
number
|
string
)
?
,
fallbackAssetId:
(
number
|
string
)
?
) →
string
Returns an asset URI.
Example:
Util.getAssetURI("rbxassetid://1234567890") -- rbxassetid://1234567890
Util.getAssetURI(1234567890) -- rbxassetid://1234567890
-- Fallback URIs
Util.getAssetURI(nil, "rbxassetid://1234567890") -- rbxassetid://1234567890 (fallback)
Util.getAssetURI(nil, 1234567890) -- rbxassetid://1234567890 (fallback)
attempt
Util.
attempt
(
runner:
(
)
→
(
)
,
maxTries:
number?
,
--
Defaults to 3
yield:
number?
) →
(
boolean
,
any
,
number
)
Calls the given function until it successfully runs. Useful for retrieving from a data store or GET/POST requests.
It will return a tuple of (success: boolean, result: any, tries: number).
Example:
local success: boolean, result: any, tries: number = Util.attempt(function()
return game:GetService("HttpService"):GetAsync("https://example.com")
end)
print(success, result)
print(`It took {tries} tries to retrieve the data`)
try
Util.
try
(
runner:
(
)
→
(
)
,
catch:
(
any
)
→
(
)
) →
any
Simple try catch function.
Example:
local result: any = Util.try(function()
return "Hello world!"
end, function(err)
warn("Error: " .. err)
end)
print(result) -- "Hello world!"
Example:
local result: any = Util.try(function()
error("Something went wrong")
end, function(err)
warn("Error: " .. err)
end)
print(result) -- nil
weld
Welds 2 parts together.
Example:
local weld: WeldConstraint = Util.weld(game.Workspace.Car.Wheel, game.Workspace.Car)
weldModel
Welds all parts in a model to the PrimaryPart if it is set.
Example:
Util.weldModel(game.Workspace.Car)
clearWelds
Clears all welds from an instance.
Example:
Util.clearWelds(game.Workspace.House)
breakJoints
Clears all joints from an instance.
Example:
Util.breakJoints(game.Workspace.House)
getMass
Gets the mass of a model.
waitForChild
Wait for a child to be added to an instance. WARNING: This function will forever wait until the child is added.
waitForPrimaryPart
Wait for the primary part of a model to be set.
addListener
Util.
addListener
(
listenerType:
string
,
--
"Property" | "Attribute"
listenTo:
string
,
--
The property or attribute to listen to
callback:
(
any
,
any
)
→
(
)
--
The callback to run when the property or attribute changes
) →
RBXScriptConnection
Expiremental
Listens to a property or attribute on an instance and runs a callback when it changes. It will return a connection that can be disconnected.
Using addListener() is an addition to Roblox's built-in GetPropertyChangedSignal() and GetAttributeChangedSignal().
The callback will be called with the previous value and the new value.
Example:
local connection = Util.addListener(
game.Workspace.NPC,
"Health",
"Attribute",
function(oldValue, newValue)
print("Health changed from " .. oldValue .. " to " .. newValue)
end
)
addPropertyListener
Shortcut for Util.addListener
Example:
local connection = Util.addPropertyListener(game.Workspace.NPC, "Name", function(oldValue, newValue)
print("Name changed from " .. oldValue .. " to " .. newValue)
end
)
addAttributeListener
Shortcut for Util.addListener
Example:
local connection = Util.addAttributeListener(game.Workspace.NPC, "Health", function(oldValue, newValue)
print("Health changed from " .. oldValue .. " to " .. newValue)
end
)
onTouch
Listens to when a part is touched by another part and runs a callback.
Example:
local connection = Util.onTouch(game.Workspace.NPC, function(part)
print(part.Name .. " was touched")
end)
onPlayerTouch
Similar to onTouch, but will only run the callback if the part is touched by a player that is alive.
Example:
local connection = Util.onPlayerTouch(game.Workspace.NPC, function(player, part)
print(player.Name .. " touched " .. part.Name)
end)
safeSet
Util.
safeSet
(
) →
boolean
--
Whether the operation was successful
Safely sets a key in an Instance or table without erroring.
Returns a boolean indicating if the operation was successful.
Example:
Util.safeSet(Workspace.Player1.Humanoid, "Health", 100)
flip
Util.
flip
(
source:
{
[
any
]
:
any
}
,
--
The table you want to flip
mergeDuplicates:
boolean?
--
Merge key duplicates into a table instead of overwriting them.
) →
{
[
any
]
:
any
}
Flips the table's keys with its values.
If mergeDuplicates
is true
, All values will be stored in a table at the key's index, instead of overwriting them.
Example:
Util.flip({ a = 1, b = 2 }) -- { [1] = "a", [2] = "b" }
Util.flip({ a = 1, b = 2 }, true) -- { [1] = { "a" }, [2] = { "b" } }
-- Use case: finding all keys with the same value
local newTable = Util.flip({ a = 1, b = 2, c = 2 }, true) -- { [1] = { "a" }, [2] = { "b", "c" } }
print(#newTable[2]) -- 2
map
Util.
map
(
source:
{
[
any
]
:
any
}
,
--
The table you want to map
callbackFn:
(
any
,
any
,
any
)
→
(
any
,
any
)
--
The function to map the table with
) →
{
[
any
]
:
any
}
Maps a table or instance to a new table.
Example:
Util.map({ 1, 2, 3 }, function(v)
return v * 2
end) -- { 2, 4, 6 }
Util.map({ 1, 2, 3 }, function(v, i)
return i * 2
end) -- { 2, 4, 6 }
filter
Util.
filter
(
source:
{
[
any
]
:
any
}
,
--
The table you want to filter
callbackFn:
(
any
,
any
,
any
)
→
(
boolean?
)
--
The function to filter the table with (element, index, source)
) →
{
[
any
]
:
any
}
Filter a table or instance to a new table.
Example:
local noTwo = Util.filter({ 1, 2, 3 }, function(value)
return value ~= 2
end) -- { 1, 3 }
local parts = Util.filter(Workspace, function(value)
return value:IsA("Part")
end) -- { Part = Instance, Part2 = Instance }
mapIndex
Util.
mapIndex
(
source:
{
[
any
]
:
any
}
,
--
The table you want to map
filterFn:
(
key:
any
,
value:
any
,
source:
any
)
→
(
value:
any
,
key:
any
)
--
The function to filter the table with
) →
{
[
any
]
:
any
}
Maps a table to a new table using the index as the key.
Includes a second argument as a function to filter the table with.
Example:
Util.mapIndex({ 1, 2, 3 }) -- { [1] = 1, [2] = 2, [3] = 3 }
Util.mapIndex({ 1, 2, 3 }, function(v)
return v * 2
end) -- { [1] = 2, [2] = 4, [3] = 6 }
Util.mapIndex({ 1, 2, 3 }, function(v, i)
return i * 2
end) -- { [2] = 2, [4] = 4, [6] = 6 }
trimWhitespace
Util.
trimWhitespace
(
text:
string
) →
string
Trims leading and trailing whitespace from a string.
Example:
Util.trimWhitespace(" Hello, world! ") -- "Hello, world!"
trimLeadingWhitespace
Util.
trimLeadingWhitespace
(
text:
string
) →
string
Trims leading whitespace from a string.
Example:
Util.trimLeadingWhitespace(" Hello, world!") -- "Hello, world!"
trimTrailingWhitespace
Util.
trimTrailingWhitespace
(
text:
string
) →
string
Trims trailing whitespace from a string.
Example:
Util.trimTrailingWhitespace("Hello, world! ") -- "Hello, world!"
split
Util.
split
(
text:
string
|
number?
,
delimiter:
string?
,
trimTrailingDelimiter:
boolean?
,
trim:
boolean?
--
Trim whitespace from each chunk
) →
{
string
}
Splits a string into a table of strings using a delimiter.
If delimiter
is not provided, it defaults to a space.
Setting trimTrailingDelimiter
to false
will result in an empty string at the end of the table if the text ends with the delimiter
Setting trim
to false
will result in whitespace not being trimmed from each chunk
Example:
Util.split("Hello, world!") -- { "Hello,", "world!" }
Util.split("Hello, world!", ", ") -- { "Hello", "world!" }
Util.split("Hello, world!", ",", nil, false) -- { "Hello", " world!" } -- no whitespace is trimmed
Util.split("Hello, world!,", ",", false) -- { "Hello", "world!", "" } -- trailing delimiter is included
Util.split("path/to/file", "/") -- { "path", "to", "file" }
Util.split("path/to/file/", "/") -- { "path", "to", "file" } -- trailing delimiter is trimmed
join
Util.
join
(
stringTable:
{
[
any
]
:
string
|
number
}
,
--
The table you want to join
separator:
string?
--
The separator to use when joining the table (defaults to ",")
) →
string
Joins a table of strings and numbers into a single string.
The string is joined using a separator, which defaults to a comma.
Example:
Util.join({"Hello", "world!"}) -- "Hello,world!"
Util.join({"Hello", "world!"}, ", ") -- "Hello, world!"
extend
Util.
extend
(
targetTable:
{
[
any
]
:
any
}
,
--
The target table you want to extend
...:
{
[
any
]
:
any
}
?
--
The tables you want to merge into the target table
) →
{
[
any
]
:
any
}
Extends a table with one or more tables.
Example:
Util.extend({ a = 1 }, { b = 2 }, { c = 3 }) -- { a = 1, b = 2, c = 3 }
Util.extend({ a = 1 }, { a = 2 }, { a = 3 }) -- { a = 3 } -- Last argument overwrites previous arguments
Util.extend({ a = 1 }, { a = 2 }, { a = 3 }, true) -- Error: 4th argument must be a table
Config override example:
local function getDefaultConfig()
return {
health = 100
}
end
local buffConfig = {
health = 150,
speed = 1.5
}
local hasBuff: boolean = true
local playerConfig: { [any]: any } = Util.extend(getDefaultConfig(), hasBuff and buffConfig) -- { health = 150, speed = 1.5 }
deepMerge
Util.
deepMerge
(
targetTable:
{
[
any
]
:
any
}
,
--
The target table you want to merge into
...:
{
[
any
]
:
any
}
--
The tables you want to merge into the target table
) →
{
[
any
]
:
any
}
Recursively merges two or more tables into one.
Example:
Util.deepMerge({ a = { b = { c = 1 } } }, { a = { b = { d = 2 } } }) -- { a = { b = { c = 1, d = 2 } } }
assign
Util.
assign
(
targetTable:
{
[
any
]
:
any
}
,
--
The target table you want to assign values to
...:
{
[
any
]
:
any
}
--
The tables you want to merge into the target table
) →
{
[
any
]
:
any
}
The assign function copies all properties from one or more source objects to a target object.
Alias for Util.extend
.
treePath
Util.
treePath
(
path:
string?
,
--
The path to the value
delimiter:
string?
--
The delimiter to use when splitting the path
) →
any
Gets a value from a table or Instance using a path.
Example:
Util.treePath({ a = { b = { c = 1 } } }, "a.b.c") -- 1
Util.treePath({ a = { b = { c = 1 } } }, "a.b") -- { c = 1 }
Util.treePath(game.Workspace, "House.Door") -- Door instance
Util.treePath(script, "NonexistantChild") -- nil
insertIf
Util.
insertIf
(
target:
{
[
any
]
:
any
}
,
--
The table you want to insert the value into
value:
any
,
--
The value you want to insert
condition:
nil
|
boolean
|
(
)
→
boolean?
--
The test condition
) →
(
)
Inserts a value into a table if the test condition is true.
Example:
Util.insertIf({ 1, 2, 3 }, 4, true) -- { 1, 2, 3, 4 }
Util.insertIf({ 1, 2, 3 }, 4, false) -- { 1, 2, 3 }
Util.insertIf({ 1, 2, 3 }, 4, function()
return true
end) -- { 1, 2, 3, 4 }
instanceChildrenToTable
Collects all children of an instance into a table.
Example:
Util.instanceChildrenToTable(game.Workspace) -- { Part = Instance, Part2 = Instance }
Util.instanceChildrenToTable(game.ReplicatedStorage.Config) -- { Config1 = CFrameValue, Config2 = StringValue }
tableLength
Util.
tableLength
(
source:
{
[
any
]
:
any
}
) →
number
Returns the total amount of values in a table.
Example:
Util.tableLength({ 1, 2, 3 }) -- 3
Util.tableLength({ a = 1, b = 2, c = 3 }) -- 3
tableRandomIndex
Util.
tableRandomIndex
(
) →
any
Returns a random index from a table or instance.
Example:
Util.tableRandomIndex({ 1, 2, 3 }) -- 2
Util.tableRandomIndex({ a = 1, b = 2, c = 3 }) -- "b"
indexOf
Util.
indexOf
(
obj:
{
[
any
]
:
any
}
,
--
The table you want to get the index from
value:
any
--
The value you want to find the index of
) →
any
Returns the index of a value in a table. This works for both dictionaries and arrays.
Example:
Util.indexOf({ 1, 2, 3 }, 2) -- 2
Util.indexOf({ a = 1, b = 2, c = 3 }, 2) -- "b"
Use table.find
for a more efficient way to find the index of a value in an array.
table.find({ 1, 2, 3 }, 2) -- 2
makeConfigFromValues
Util.
makeConfigFromValues
(
) →
{
[
string
]
:
any
}
Creates a nested table of value instances from a Folder or Configuration instance.
Example:
- Config (Folder) -- in ReplicatedStorage
- Origin (CFrameValue), Value = CFrame.new(0, 1, 0)
- WelcomeMessage (StringValue), Value = "Hello, world!"
Util.makeConfigFromValues(game.ReplicatedStorage.Config)
Result:
{
Origin = CFrame.new(0, 1, 0),
WelcomeMessage = "Hello, world!"
}
tableRemove
Util.
tableRemove
(
removeTest:
number
|
{
any
}
|
(
any
,
number
,
number
)
→
boolean
--
The value to remove or reducing function to use
) →
(
)
Removes a value from a table or instance.
Example:
Util.tableRemove({ 1, 2, 3 }, 2) -- { 1, 3 }
Util.tableRemove({ 1, 2, 3 }, { 2, 3 }) -- { 1 }
Util.tableRemove({ 1, 2, 3 }, function(value, newIndex, i)
return value == 2
end) -- { 1, 3 }
waterfall
Util.
waterfall
(
tasks:
{
(
...any
)
→
...any
}
,
--
The tasks to execute
finalCallback:
(
err:
any
,
...any
)
→
(
)
--
The final callback to execute
) →
(
)
Executes a series of tasks in a waterfall fashion.
Example:
Util.waterfall(
function(a, b, callback)
print("Task 1:", a, b)
callback(nil, "Task 1 result")
end,
function(result, callback)
print("Task 2:", result)
callback(nil, "Task 2 result")
end,
function(result, callback)
print("Task 3:", result)
callback(nil, "Task 3 result")
end,
function(err, result)
if err then
print("Error:", err)
else
print("Final result:", result)
end
end
)
generateUUID
Util.
generateUUID
(
) →
string
Generates a UUID/GUID (Universally Unique Identifier) random string using HttpService:GenerateGUID.
timeout
Util.
timeout
(
delay:
number
,
callback:
function
) →
(
)
Alternative for task.delay
.
Runs a function after delay
seconds.
Returns the time elapsed in seconds.
Example:
Util.timeout(1, function(elapsedTime: number)
print("Hello, world!")
end)
interval
Runs a function every interval
in seconds.
Return false
within the callback to stop the interval or call :Disconnect()
on the returned RBXScriptConnection
.
This function returns an RBXScriptConnection
that can be disconnected to stop the interval.
Example:
Util.interval(1, function(elapsedTime: number, deltaTime: number)
print(elapsedTime)
end)
inTable
Util.
inTable
(
searchTable:
{
[
any
]
:
any
}
,
target:
any
) →
boolean
Checks if a value is in a table.
Example:
Util.inTable({ 1, 2, 3 }, 2) -- true
Util.inTable({ 1, 2, 3 }, 4) -- false
Util.inTable({ Part, 2, 3, Part2 = true }, Part) -- true