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

Using Remote Functions to send data?

Asked by 6 years ago
local function TriggerRecieved()
print("We got your request. Processing now.")

end


RequestData.OnServerInvoke = TriggerRecieved
end)

So this is the only section that matters. I have what i call a slingshot event. One server script fires the local script, and the local script fires #2 script for information from within that script.

How can i use Remote functions to send variables back to the client sided script if possible ?

1 answer

Log in to vote
0
Answered by
Jellyfosh 125
6 years ago

Keep in mind that Remote FUNCTIONS are used to relay data from server to client and vice versa. This means that info will be passed somewhat like this: ServerInputToClient > ClientRecievesInput > ClientInputToServer > ServerRecievesClientInput.

If you are only trying to do something like ServerImputToClient > ClientRecievesInput then you want to be using Remote EVENTS. I only tell you this because sometimes people will use remote functions when they really only need to use a remote event.

Here's an example of how to set up a remote function in which the client would request something from the server and return it to the client:

-- In your Local Script
local repStorage= game:GetService("ReplicatedStorage")
local requestData = repStorage:WaitForChild("DataRequest")
local request = requestDatat:InvokeServer() --This means that request will be whatever your Server Script returns 

--In your Server Script
local repStorage= game:GetService("ReplicatedStorage")

local dataRequest = Instance.new("RemoteFunction",repStorage)
dataRequest.Name = "DataRequest"

local function DataRequested(player)
    local request = DEFINEREQUESTHERE
    return request --this sends the variable "request" to your local script
end

dataRequest.OnServerInvoke = DataRequested --This means that whenever the server is invoked the DataRequested function will trigger.
0
Ok but how would i reference that data sent to the local script in the local script? TreySoWavvy 18 — 6y
0
That would be your "request". The server returns its definition of "request" to the client, making "requestDatat:InvokeServer()" whatever its definition in the server was. Jellyfosh 125 — 6y
Ad

Answer this question