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:
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.
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:
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
Game.ReplicatedStorage:WaitForChild("RemoteFunction1")
RF.OnClientInvoke = function(param)
print(param)
end
RF:InvokeServer("TestString")
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.
1 comment
uhhhhhhhhh