NetFunction
Wrapper for Roblox's RemoteFunctions
Functions
Load
Types
interface
LoadOptions {
id:
string
--
the unique idenitifier
}
Load a Roket NetFunction
Read more on the docs.
Define
Define the function on the client, the server, or both
In the passed function, the player
is nil
only when the function is being called locally by the server.
Examples
See Examples in the docs.
Errors
Type | Description |
---|---|
ALREADY_DEFINED | The function has already been defined by the runtime |
CallLocal
NetFunction:
CallLocal
(
...:
any
) →
...any
Call the raw defined function locally.
Can only be called on the client.
If you meant to locally call the function on the server, just call the function without passing the first "player(s)" arg myFunction("my data")
Errors
Type | Description |
---|---|
NOT_CLIENT | The function didn't get called on the client |
NetFunction()
Calls the NetFunction either remotely or locally.
- Remotely being from the Client to the Server or from the Server to the Client(s)
- Locally being ran client-side if executed on the Client or ran server-side if executed on the Server
When calling the function locally, actual return values are returned instead of a Promise.
When calling the function remotely, a Promise is returned,
containing either the actual return values
(if the call was targeted towards a single entity - that is either from Client to Server or from Server to specific Client)
or a map of Player -> {...rets}
if the call was targeted to multiple entities (that is from Server to multiple Clients).
Below is a cheatsheet illustrating when a function is being called remotely or locally, and what are it's return values for any given call.
Cheatsheet
--#server
func(...) -- local call, returns ...rets
func(player, ...) -- remote call to specific client, returns Promise<...rets>
func([plr1, plr2], ...)-- remote call to specific clients, returns Promise<{[Player]: {...rets}}>
func(game.Players, ...)-- remote call to all clients, returns Promise<{[Player]: {...rets}}>
--#client
func(...) -- remote call to the server, returns Promise<...rets>
func:CallLocal(...) -- local call, returns ...rets
Examples
local MathService = {
Add = Roket.NetFunction "Add"
}
function MathService.RoketStart()
--#server
MathService.Add:Define(function(resolve, player, a, b)
resolve(a + b)
end)
--#client
task.wait(3)
MathService.Add(3, 5):andThen(print)
--#end
end
return MathService
See more Examples in the docs.