Skip to main content

Startup

Starts the library and tells you when it is ready.

The server compiles the SOUNDS Configuration into the schema once. Every client receives that schema when it joins. Until a side has started, the rest of the library warns once per function and returns blank sounds, nil or empty results, so other scripts should wait with WaitUntilReady or OnReady.

Nothing here throws into your game code: calling an Init function twice, on the wrong side or with a bad argument prints a warning, and a failure while starting turns sounds off with a warning. A client gives up on the schema after 30 seconds, so a server that could not start never holds a client's script forever.

Functions​

InitServer​

This item only works when running on the server. Server
Startup.InitServer(
soundFolder: Configuration--

The SOUNDS Configuration.

) → ()

Compiles the SOUNDS Configuration into the schema, publishes it to clients, and destroys the Configuration.

DANGER

Call this once. The schema is locked after it is built, so sounds and SoundGroups cannot be added while the game runs.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")

local VluxySF = require(ReplicatedStorage.Packages.VluxySF)

VluxySF.Startup.InitServer(ServerStorage.SOUNDS)

InitClient​

This item only works when running on the client. ClientThis is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
Startup.InitClient(
timeout: number?--

How long to wait for the preloads, in seconds. Default is 5. 0 does not wait.

) → ()

Receives the schema from the server, then builds and preloads every sound tagged for preloading. It can be called from ReplicatedFirst, for example to play sounds on a loading screen; it waits for the schema to arrive. If the schema has not arrived after 30 seconds, because the server could not start, it warns and returns with sounds off for this player.

The library is ready as soon as the schema is received, so WaitUntilReady and OnReady in other scripts resume then. This call itself yields until the preloads finish or timeout seconds pass, whichever comes first, and warns if it timed out. Pass 0 to not wait at all: the preloads still run in the background, no warning is printed, and you can check on them with IsPreloaded or WaitUntilPreloaded.

DANGER

Call this once per client.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local VluxySF = require(ReplicatedStorage.Packages.VluxySF)

VluxySF.Startup.InitClient(4)

IsReady​

Startup.IsReady() → boolean--

Whether the library has started on this side.

print(VluxySF.Startup.IsReady())

WaitUntilReady​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
Startup.WaitUntilReady(
timeout: number?--

The longest to wait, in seconds. Waits forever when not given.

) → boolean--

true once ready, false if the timeout passed first.

Yields until the library has started on this side, or until timeout seconds pass. Returns right away if it already has.

VluxySF.Startup.WaitUntilReady()

VluxySF.OneShot("MySound")
if not VluxySF.Startup.WaitUntilReady(10) then
	warn("Sounds did not start within 10 seconds")
end

OnReady​

Startup.OnReady(
callback: () → ()--

Runs once the library is ready.

) → () → ()--

Cancels the callback if it has not run yet.

Runs the callback once the library has started, without yielding. If it already has, the callback runs in a new thread right away. An error in the callback does not stop startup or other callbacks.

VluxySF.Startup.OnReady(function()
	VluxySF.OneShot("MySound")
end)

-- This line does not wait.

IsPreloaded​

Startup.IsPreloaded() → boolean--

Whether the sounds tagged for preloading have finished loading. Always true on the server

print(VluxySF.Startup.IsPreloaded())

once it has started, since the server preloads nothing.

WaitUntilPreloaded​

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
Startup.WaitUntilPreloaded(
timeout: number?--

The longest to wait, in seconds. Waits forever when not given.

) → boolean--

true once preloaded, false if the timeout passed first.

Yields until the sounds tagged for preloading have finished loading, or until timeout seconds pass. Returns right away if they have. Useful after InitClient(0).

VluxySF.Startup.InitClient(0)

-- Do other startup work here.

VluxySF.Startup.WaitUntilPreloaded()
Show raw api
{
    "functions": [
        {
            "name": "InitServer",
            "desc": "Compiles the `SOUNDS` Configuration into the schema, publishes it to clients, and destroys the Configuration.\n\n:::danger\nCall this once. The schema is locked after it is built, so sounds and SoundGroups cannot be added while the game\nruns.\n:::\n\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\nlocal ServerStorage = game:GetService(\"ServerStorage\")\n\nlocal VluxySF = require(ReplicatedStorage.Packages.VluxySF)\n\nVluxySF.Startup.InitServer(ServerStorage.SOUNDS)\n```",
            "params": [
                {
                    "name": "soundFolder",
                    "desc": "The `SOUNDS` Configuration.",
                    "lua_type": "Configuration"
                }
            ],
            "returns": [],
            "function_type": "static",
            "realm": [
                "Server"
            ],
            "source": {
                "line": 128,
                "path": "lib/Api/Startup.luau"
            }
        },
        {
            "name": "InitClient",
            "desc": "Receives the schema from the server, then builds and preloads every sound tagged for preloading. It can be\ncalled from `ReplicatedFirst`, for example to play sounds on a loading screen; it waits for the schema to arrive.\nIf the schema has not arrived after 30 seconds, because the server could not start, it warns and returns with\nsounds off for this player.\n\nThe library is ready as soon as the schema is received, so `WaitUntilReady` and `OnReady` in other scripts resume\nthen. This call itself yields until the preloads finish or `timeout` seconds pass, whichever comes first, and\nwarns if it timed out. Pass `0` to not wait at all: the preloads still run in the background, no warning is\nprinted, and you can check on them with `IsPreloaded` or `WaitUntilPreloaded`.\n\n:::danger\nCall this once per client.\n:::\n\n```lua\nlocal ReplicatedStorage = game:GetService(\"ReplicatedStorage\")\n\nlocal VluxySF = require(ReplicatedStorage.Packages.VluxySF)\n\nVluxySF.Startup.InitClient(4)\n```",
            "params": [
                {
                    "name": "timeout",
                    "desc": "How long to wait for the preloads, in seconds. Default is 5. `0` does not wait.",
                    "lua_type": "number?"
                }
            ],
            "returns": [],
            "function_type": "static",
            "realm": [
                "Client"
            ],
            "yields": true,
            "source": {
                "line": 222,
                "path": "lib/Api/Startup.luau"
            }
        },
        {
            "name": "IsReady",
            "desc": "```lua\nprint(VluxySF.Startup.IsReady())\n```",
            "params": [],
            "returns": [
                {
                    "desc": "Whether the library has started on this side.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 312,
                "path": "lib/Api/Startup.luau"
            }
        },
        {
            "name": "WaitUntilReady",
            "desc": "Yields until the library has started on this side, or until `timeout` seconds pass. Returns right away if it\nalready has.\n\n```lua\nVluxySF.Startup.WaitUntilReady()\n\nVluxySF.OneShot(\"MySound\")\n```\n\n```lua\nif not VluxySF.Startup.WaitUntilReady(10) then\n\twarn(\"Sounds did not start within 10 seconds\")\nend\n```",
            "params": [
                {
                    "name": "timeout",
                    "desc": "The longest to wait, in seconds. Waits forever when not given.",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "`true` once ready, `false` if the timeout passed first.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "yields": true,
            "source": {
                "line": 340,
                "path": "lib/Api/Startup.luau"
            }
        },
        {
            "name": "OnReady",
            "desc": "Runs the callback once the library has started, without yielding. If it already has, the callback runs in a new\nthread right away. An error in the callback does not stop startup or other callbacks.\n\n```lua\nVluxySF.Startup.OnReady(function()\n\tVluxySF.OneShot(\"MySound\")\nend)\n\n-- This line does not wait.\n```",
            "params": [
                {
                    "name": "callback",
                    "desc": "Runs once the library is ready.",
                    "lua_type": "() -> ()"
                }
            ],
            "returns": [
                {
                    "desc": "Cancels the callback if it has not run yet.",
                    "lua_type": "() -> ()"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 362,
                "path": "lib/Api/Startup.luau"
            }
        },
        {
            "name": "IsPreloaded",
            "desc": "```lua\nprint(VluxySF.Startup.IsPreloaded())\n```\n\nonce it has started, since the server preloads nothing.",
            "params": [],
            "returns": [
                {
                    "desc": "Whether the sounds tagged for preloading have finished loading. Always `true` on the server",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 386,
                "path": "lib/Api/Startup.luau"
            }
        },
        {
            "name": "WaitUntilPreloaded",
            "desc": "Yields until the sounds tagged for preloading have finished loading, or until `timeout` seconds pass. Returns right\naway if they have. Useful after `InitClient(0)`.\n\n```lua\nVluxySF.Startup.InitClient(0)\n\n-- Do other startup work here.\n\nVluxySF.Startup.WaitUntilPreloaded()\n```",
            "params": [
                {
                    "name": "timeout",
                    "desc": "The longest to wait, in seconds. Waits forever when not given.",
                    "lua_type": "number?"
                }
            ],
            "returns": [
                {
                    "desc": "`true` once preloaded, `false` if the timeout passed first.",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "yields": true,
            "source": {
                "line": 410,
                "path": "lib/Api/Startup.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Startup",
    "desc": "Starts the library and tells you when it is ready.\n\nThe server compiles the `SOUNDS` Configuration into the schema once. Every client receives that schema when it\njoins. Until a side has started, the rest of the library warns once per function and returns blank sounds, `nil`\nor empty results, so other scripts should wait with `WaitUntilReady` or `OnReady`.\n\nNothing here throws into your game code: calling an `Init` function twice, on the wrong side or with a bad\nargument prints a warning, and a failure while starting turns sounds off with a warning. A client gives up on\nthe schema after 30 seconds, so a server that could not start never holds a client's script forever.",
    "source": {
        "line": 35,
        "path": "lib/Api/Startup.luau"
    }
}