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. ServerCompiles 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. YieldsStartup.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. YieldsStartup.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. YieldsStartup.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()