FunctionLib
A collection of general-purpose utility functions used throughout Hydrogen — number formatting, string/table helpers, and dictionary utilities.
Number Formatting
ToSuffixString
Converts a number into a shortened, suffixed string. Gives a string to 3 decimal places by default. (e.g. 1000 → 1.000K). Pass in a second parameter to control how many decimal places to return the value to.
Hydrogen.FunctionLib:ToSuffixString(1500000) --> "1.500M"
Hydrogen.FunctionLib:ToSuffixString(1500000, 1) --> "1.5M"ToScientificNotation / ToRegularNumber
Converts between a regular number and scientific notation string.
Hydrogen.FunctionLib:ToScientificNotation(1500) --> "1.5e3"
Hydrogen.FunctionLib:ToRegularNumber("1.5e3") --> 1500WARNING
ToRegularNumber expects the exact format returned by ToScientificNotation ("Ae+B" or "Ae-B"). Malformed strings will error.
Time
SecsToMins
Converts seconds into minutes/seconds, either as a table or formatted string.
Hydrogen.FunctionLib:SecsToMins(90) --> { Mins = 1, Secs = 30 }
Hydrogen.FunctionLib:SecsToMins(90, true) --> "1:30"
Hydrogen.FunctionLib:SecsToMins(45, true) --> "45s"Strings & Tables
FindPossibleStringsInString
Returns the first value from Values that appears inside String, or nil.
Hydrogen.FunctionLib:FindPossibleStringsInString("HelloWorld", { "World", "Foo" }) --> "World"FindStringsInTable
Returns true only if every string in Strings also exists in Values.
Hydrogen.FunctionLib:FindStringsInTable({ "A", "B" }, { "A", "B", "C" }) --> trueFindFirstDescendant
Same idea as FindFirstChild, but searches all descendants for a matching name.
Hydrogen.FunctionLib:FindFirstDescendant(SomeFolder, "Explosion")WARNING
If multiple descendants share the same name, the last one found is returned, not necessarily the first in hierarchy order.
Instances
CheckIfPartIsPlayer
Checks whether a BasePart's parent is a character model (has a Humanoid).
Hydrogen.FunctionLib:CheckIfPartIsPlayer(Hit) --> true / falseUseful in Touched events to filter for player characters.
Dictionaries
TIP
MergeDictionary and CopyDeep are adapted from Sift — credit to cxmeel and contributors.
MergeDictionary
Merges any number of dictionaries into one. Later tables override earlier ones.
Hydrogen.FunctionLib:MergeDictionary({ A = 1, B = 2 }, { B = 3 }) --> { A = 1, B = 3 }WARNING
Setting a key's value to Hydrogen.FunctionLib.None removes it from the result — useful for deleting a key during a merge rather than overwriting it.
CopyDeep
Returns a full deep copy of a table, including nested tables.
local Copy = Hydrogen.FunctionLib:CopyDeep(OriginalTable)