How to invoke remoteFunction?

Hello I have forgotten how to setup an invoke connection for my remote function so that I can use a local script to communicate to a server script. However, I have looked at the documentation and it is nothing short of trash. I wish they did not remove the old examples all the pages used to have. So annoying & stupid! Anyways can somebody help me out? :expressionless:

--ServerSide code
local connections = {} --used for the function below.
Functions["CreateConnection"] = function(remoteFunc)
	--This function will allow communication between client and server sides.
	
	--remove any existing connections:
	for nam,obj in pairs(connections) do
		print(connections)
		if typeof(obj) == 'function' or typeof(obj) == 'RBXScriptConnection' then
			obj:Disconnect() --disconnect any functions
		end
		
		task.wait(0.1)
		obj = nil
	end
	
	--Create a new connection:
	local newVal = Instance.new("BoolValue")
	newVal.Name = "Connection"
	
	-- Create a new connection:
	connections[newVal] = remoteFunc.OnServerInvoke:Connect(function(data)
		print(data, "<---")

		-- Handle the data received from the client here
	end)
	newVal:Destroy() --remove the value as we wont need it anymore.
end
--serverSide code
local clientSide_Communicator = Instance.new("RemoteFunction")
clientSide_Communicator.Name = "Connection"
Functions["CreateConnection"](clientSide_Communicator)
clientSide_Communicator.Parent = data.model

09:25:29.387 OnServerInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available - Studio

I am using a remoteFunction.

You can find many examples here: Remote Events and Callbacks | Documentation - Roblox Creator Hub

OnServerInvoke is a property you put functions in, not an event.

RemoteFunction.OnServerInvoke = function()
	print("Hello World")
	return true
end

You have to use a function that calls all the functions you ever need.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.