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

Using Remote Functions to send data?

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

✓ Accepted answer

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.

2 comments

0

Ok but how would i reference that data sent to the local script in the local script?

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.

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