Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to use BindableFunction?

I want to make a connection between a normal script and a Local Script.

Do I need to use the BindableFunction object? If yes, How? If relevant, where do I put the BindableFunction object(s)? What script do I type (and where?) to enable BindableFunction?

Thanks to anyone who helps me.

1 comment

0

uhhhhhhhhh

2 answers

What you're looking for is a RemoteFunction, not a BindableFunction. BindableFunctions and *Events are Script<->Script and LocalScript<->LocalScript only, Remote*s are Script<->LocalScript only.

To use a RemoteFunction, you have to first create one, either using the Basic Objects set in Studio, or by doing:

--Script
local RF = Instance.new("RemoteFunction")

Where it is parented to is not important, so long as both the Client and Server can access it. ReplicatedStorage is a good place for this reason.

--Script
local RF = Instance.new("RemoteFunction", Game.ReplicatedStorage")

Now, to use it obviously requires a LocalScript. It's fairly simple stuff, once you get the hang of it:

--Script
local RF = Instance.new("RemoteFunction", Game.ReplicatedStorage")
RF.Name = "RemoteFunction1" --Default is simply "RemoteFunction"

RF.OnServerInvoke = function(plr, param) --When the Client (LocalScript) calls the 'InvokeServer' method of the RemoteFunction, this is the function that gets called. 'plr' is the Player associated with the Client that invoked the RemoteFunction.
	print(param)
	RF:InvokeClient(plr, param .. "_returned") --Invokes a specific Client.
end
--LocalScript
Game.ReplicatedStorage:WaitForChild("RemoteFunction1") --So we don't error

RF.OnClientInvoke = function(param) --Server invokes the RemoteFunction. Notice the lack of the 'plr' parameter.
	print(param)
end

RF:InvokeServer("TestString") --Invokes the RemoteFunction from the Client side. Again, notice the lack of 'plr'

When run, these two scripts together will print "TestString" to the Server's Output, and "TestString_returned" to the Client's output.

These differ from RemoteEvent objects in that you have to invoke individual clients one at a time, and can only have a single function assigned to the RemoteFunction. However, they will, unlike RemoteEvents and BindableEvents, wait until the called function returns, allowing you to use them like regular functions. Remote* and BinableEvents do not allow you to return data.

I can help you with basics of BindableFunction;

Activation (In BindableFunction)

script.Parent.OnInvoke = function(parameter1,parameter2)
print(parameter1.." followed by "..parameter2)
end

Activation (In Script/LocalScript)

bf = game.Workspace.BindableFunction

bf.Invoke("You are being","an awesome scripter")

About, your 'connection', explain more what you mean...

Hope it helpes! Thanks, marcoantoniosantos3.

This discussion is preserved as it was. New answers, comments, and votes are closed.