Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to use BindableFunction?

Asked by 9 years ago

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.

0
uhhhhhhhhh Exllumina 10 — 9y

2 answers

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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.

Ad
Log in to vote
-1
Answered by 9 years ago

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.

Answer this question