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!