Skip to content

Instantly share code, notes, and snippets.

View XoifaiI's full-sized avatar

XNX XoifaiI

View GitHub Profile
@XoifaiI
XoifaiI / Connections.luau
Created October 4, 2025 23:58
Easy way to bulk manage RBXConnections
--!strict
local Connections = {}
Connections.__index = Connections
type Connection = RBXScriptConnection
type ConnectionsData = {
Connections: {Connection},
}
@XoifaiI
XoifaiI / WaitForChildOfClassAsync.luau
Created October 4, 2025 23:29
Blocking wait for a child instance of a specific class type
--!strict
return function(ParentObject: Instance, TargetClassName: string): Instance
local FoundChild = ParentObject:FindFirstChildOfClass(TargetClassName)
while not FoundChild do
ParentObject.ChildAdded:Wait()
FoundChild = ParentObject:FindFirstChildOfClass(TargetClassName)
end
return FoundChild
end
@XoifaiI
XoifaiI / ExpoTween.luau
Created October 4, 2025 23:27
Custom easing curve with control over where the transition is greatest
--!strict
local Epsilon = 0.001
return function(Alpha: number, Midpoint: number): number
Midpoint = math.clamp(Midpoint, Epsilon, 1 - Epsilon)
Alpha = math.clamp(Alpha, 0, 1)
local function CalculateIncreasing(): number
return 1 - 2 ^ (-10 * Alpha / Midpoint)
@XoifaiI
XoifaiI / WaitForFirstAsync.luau
Created October 4, 2025 23:25
Runs multiple callback functions concurrently and returns the result of whichever completes first
--!strict
return function(...: (...any) -> ...any): ...any
local CurrentThread = coroutine.running()
local HasResumed = false
local CaughtError
local function ResumeThread(...: any)
if HasResumed then
return
@XoifaiI
XoifaiI / SetSequentialInterval.luau
Created October 4, 2025 23:24
Each execution waits for the previous one to complete before doing the next one
--!strict
local function SetSequentialInterval(CallbackFunction: (number, ...any) -> (), IntervalDuration: number, ...: any): () -> ()
local IsCleared = false
local function ExecuteCallback(ScheduledTimestamp: number, ...: any)
if IsCleared then
return
end
local TimeDelta = os.clock() - ScheduledTimestamp
@XoifaiI
XoifaiI / FormatTable.luau
Last active October 5, 2025 00:51
Makes a luau table easily readable
--!strict
local MaximumDepth = 4
local IndentString = " "
local function FormatValue(Value: any, CurrentDepth: number, IsKey: boolean?): string
CurrentDepth = CurrentDepth or 0
if CurrentDepth >= MaximumDepth then
return "{ ... }"
end
@XoifaiI
XoifaiI / RetryAsync.luau
Created October 4, 2025 23:20
Retries a function with a expo backoff
--!strict
type ExecutableFunction = (...any) -> ...any
export type Handler = (...any) -> (boolean, ...any)
local function RetryAsync(Func: ExecutableFunction, MaximumAttempts: number, PauseConstantValue: number?, PauseExponentValue: number?, CustomHandler: Handler?): (boolean, ...any)
local PauseConstant: number = PauseConstantValue or 0
local PauseExponent: number = PauseExponentValue or 0
local ExecutionHandler: Handler = CustomHandler or pcall
@XoifaiI
XoifaiI / IterateOverPagesAsync.luau
Created October 4, 2025 23:18
Iterate over pages
--!strict
type Pages = {
GetCurrentPage: (self: Pages) -> { { KeyName: any } },
AdvanceToNextPageAsync: (self: Pages) -> (),
IsFinished: boolean,
}
return function(PagesObject: Pages): () -> (any, number)
return coroutine.wrap(function()
@XoifaiI
XoifaiI / NoYield.luau
Created October 4, 2025 23:16
Prevents a given callback from yielding
--!strict
type CallbackFunction = (...any) -> ...any
local function HandleResult(Thread: thread, Success: boolean, ...: any): ...any
if not Success then
error(debug.traceback(Thread, (...)), 2)
end
if coroutine.status(Thread) == "dead" then
error("Do not yield inside a changing event")
@XoifaiI
XoifaiI / SafePlayerAdded.luau
Last active October 4, 2025 23:16
Makes sure every player is accounted for, only once
--!strict
local Players = game:GetService("Players")
return function(OnPlayerAddedCallback: (Player) -> nil)
local ProcessedPlayers = {}
local function SafeCallback(Player)
if not ProcessedPlayers[Player] then
ProcessedPlayers[Player] = true
OnPlayerAddedCallback(Player)