CHEAT SHEET: Remote Events/Functions, Bindable Events/Functions

Hi all!

I put some time into making a reference sheet on how to use remote events, remote functions, bindable events, bindable functions, and unreliable remote events. I added pictures and symbols to hopefully make it easier to jog your memory. (If these are brand new concepts, however, you should still take a look at the docs!) Hopefully this will help cut down on time spent re-reading docs.

I’ve introduced some novel representations for each topic. Like, a remote function gets a big ? (because it expects an response in return) and an arrow from server to client (although the reverse is also possible) since it crosses the client-server boundary.

If you’re feeling generous, I’d appreciate any reviews of accuracy!

24 Likes

do bindable function have a usecase?

Well yeah, obviously. If they were useless or another instance is recommended over binadables then they would be deprecated and eventually removed.

Good question, I had to think on it! Here’s a potential scenario:

Imagine your game involves a town with a shop, as well as billboards all over to advertise what that shop is selling. So, you have a server-side script BillboardManager to handle the billboards: it keeps track of all of them, it has functions to update them, as well as other billboard-related tasks.

Let’s assume you’re also using a script to manage the shop in your game, ShopScript, and it records how much of each product is in stock:

local stockOfProducts = {
    ["apples"] = 4,
    ["berries"] = 17
}

local function sellItem(buyer: Player, item: string)
    (add item to buyer inventory)
    (remove one of the item from stockOfProducts)
end

The BillboardManager needs to check the stock of items. So, it uses a BindableFunction, because it’s asking a question that it needs an answer to (hence, a BindableFunction, and not a BindableEvent), and it’s asking another script that’s on the same side of the client-server boundary (they’re both server-side in this example). So, BillboardManager might contain:

-- This is the BindableFunction
local inventoryQuery = ReplicatedStorage.storeInventoryQueryEvent

-- ...and here is where it's asking its question!
local appleStock = inventoryQuery:invoke("apples")

if appleStock > 0 then
    (apply apple ads to billboards)
end

and the StoreScript might look like:

local inventoryQuery = ReplicatedStorage.storeInventoryQueryEvent

local stockOfProducts = {
    ["apples"] = 4,
    ["berries"] = 17
}

... other code ...

local function getProductStock(productName: string)
    return stockOfProducts[productName]
end

inventoryQuery.OnInvoke = getProductStock

and this way, when the BillboardManager invokes the BindableFunction and passes in “apples,” the StoreScript grabs the number of apples in stock from its table.

This all comes down to how you want to split things up. Maybe you’d rather have the shop’s code and the billboard code all in one script. Then, this wouldn’t be necessary. But, as scripts get longer and more complicated, it’s usually better to start splitting things up.

Hopefully this was a helpful example!

1 Like

yes

not that kind of use case, i mean how they used in a scenario and such.

Weapon systems use bindables. Look at the example template for their fps system.

1 Like