Skip to content

Client 1.1

For Client-sided operations.

Getting the Client Object

lua
local Client = Warp.Client()

.awaitReady yield

Yields the current thread until the client has successfully initialized and synchronized with the server's replication data (identifier).

INFO

Its optionally, but highly recommended to call this before firing or connecting to any events to ensure the network is fully ready.

luau
() -> ()
luau
local Client = Warp.Client()

-- wait for the client to be fully initialized
Client.awaitReady()

print("Client is now ready to send and receive events! :D")

.Connect

Connect to an event to receive incoming data from the server.

luau
(
	remoteName: string,
	fn: (...any) -> ...any
) -> Connection
luau
local connection = Client.Connect("ServerNotify", function(message, sender)
	print(`Server message from {sender}: {message}`)
end)
print(connection.Connected)

.Once

Similar to :Connect but automatically disconnects after the first firing.

luau
(
	remoteName: string,
	fn: (...any) -> ...any
) -> Connection
luau
Client.Once("WelcomeMessage", function(welcomeText)
	print(`Welcome: {welcomeText}`)
end)

.Wait yield

Wait for an event to be triggered.

luau
(
	remoteName: string
) -> (number, ...any)
luau
local elapsed, message = Client.Wait("ServerMessage")
print(`Received message after {elapsed} seconds: {message}`)

.Disconnect

Disconnect the event connection.

luau
()
luau
local connection = Client.Connect("ServerNotify", function(message, sender)
	print(`Server message from {sender}: {message}`)
	-- Disconnect the connection
	connection:Disconnect()
end)
print(Connection.Connected)

.DisconnectAll

Disconnect all connections for a specific event.

luau
(
	remoteName: string
)
luau
Client.DisconnectAll("ServerNotify")

.Destroy

Disconnect all connections and remove the event.

luau
(
	remoteName: string
)
luau
Client.Destroy("ServerNotify")

.Fire

Fire an event to the server.

luau
(
	remoteName: string,
	reliable: boolean,
	...: any
)
luau
-- (TCP) Reliable event (guaranteed delivery)
Client.Fire("PlayerAction", true, "jump", playerPosition)

-- (UDP) Unreliable event (faster but not guaranteed)
Client.Fire("PositionUpdate", false, currentPosition)

.Invoke yield

Invoke the server with timeout support.

luau
(
	remoteName: string,
	timeout: number?,
	...: any
) -> ...any
luau
local Client = Warp.Client()
local response = Client.Invoke("RequestData", 3, "playerStats")
if response then
	print("Server responded:", response)
else
	print("Request timed out")
end

WARNING

This function is yielded. Returns nil if timeout occurs.

.useSchema

Define a schema for strict data packing on a specific event.

luau
(
	remoteName: string,
	schema: Buffer.SchemaType
)
luau
local Client = Warp.Client()

-- Define a schema for position updates
local positionSchema = Client.Schema.struct({
	x = Client.Schema.f32,
	y = Client.Schema.f32,
	z = Client.Schema.f32,
	timestamp = Client.Schema.u32
})
-- Define a schema for data updates
local dataSchema = Client.Schema.struct({
	Coins = Client.Schema.u32,
	Level = Client.Schema.u8,
	Inventory = Client.Schema.array(Client.Schema.u32),
	Settings = Client.Schema.struct({
		VFX = Client.Schema.boolean,
		Volume = Client.Schema.f32,
		Language = Client.Schema.string,
	})
})

-- Now this event will use the schema
Client.useSchema("DataReplication", dataSchema)
Client.useSchema("PositionUpdate", positionSchema)
Client.Connect("PositionUpdate", function(x, y, z, timestamp)
	-- Data is automatically deserialized according to schema
	updatePlayerPosition(x, y, z)
end)

.Schema

Access to Buffer.Schema for creating data schemas.