Skip to content

Client

A Client-sided Connection

.new

Create new FastNet2 event

lua
(
	Identifier: string,
	reliable: boolean
)
(
	Identifier: string,
	reliable: boolean
)
lua
local Remote = FastNet2.new("Remote", false) -- is unreliable event
local Remote2 = FastNet2.new("Remote", true) -- is reliable event
local Remote3 = FastNet2.new("Remote") -- is also reliable event
local Remote = FastNet2.new("Remote", false) -- is unreliable event
local Remote2 = FastNet2.new("Remote", true) -- is reliable event
local Remote3 = FastNet2.new("Remote") -- is also reliable event

Identifier will converte/encode into hash identifier

:Connect or :Listen

Listen an event from the server to receive, :Connect and :Listen is the same function.

lua
(
	player: Player,
	callback: (...any) -> ()
)
(
	player: Player,
	callback: (...any) -> ()
)
lua
Remote:Connect(function(player, ...)
	print(...)
end)
Remote:Connect(function(player, ...)
	print(...)
end)
lua
-- to know if the event is connected or not by doing `.Connected`
print(Remote.Connected)
-- to know if the event is connected or not by doing `.Connected`
print(Remote.Connected)

Each event only allowed have one callback.

:Once

This function is same as :Connect but it disconnect the event once it fired.

lua
(
	player: Player,
	callback: (...any) -> ()
)
(
	player: Player,
	callback: (...any) -> ()
)
lua
Remote:Once(function(player, ...)
	print(...)
end)
Remote:Once(function(player, ...)
	print(...)
end)

:Disconnect

Disconnect the event

lua
Remote:Disconnect()
Remote:Disconnect()

:Fire

Fire the event to the spesific server with data.

lua
(
	...: any
)
(
	...: any
)
lua
Remote:Fire("Hello World!")
Remote:Fire("Hello World!")

WARNING

This function have rate limiting to prevent spamming

:Invoke

Semiliar with :InvokeServer, its for doing Invoke to a Server.

lua
(
	timeout: number,
	...: any
) -> (...any)
(
	timeout: number,
	...: any
) -> (...any)
lua
local Request = Remote:Invoke(2, "Hello World!")
local Request = Remote:Invoke(2, "Hello World!")

WARNING

This function is yielded, and the minimum for timeout is 2 (seconds)

:Wait

Wait the event that triggered/pinged

lua
Remote:Wait()
Remote:Wait()

WARNING

This function is yielded

:Destroy

Disconnect the event and Remove the event from FastNet2

lua
Remote:Destroy()
Remote:Destroy()