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

I need to know how remote function works?

So like I need to create a script to take items out of an inventory and clone a block and change the position using mouse movements and mouse.hit.position

a lot of work.

But I figured I need a RemoteFunction based off of what the wiki says because I want to send variable arguments from the client to the server and change some of those arguments in the server script and then send them back into the client.

I really don't know how RemoteFunctions work. I looked at the wiki about it and found about InvokeServer and InvokeClient and OnServerInvoke

I figured it would work like this

-- local script
local remotefunction = wherever.it.is
--<code, functions, if statements, variables>
remotefunction:InvokeServer(Variable1, Variable2)

then we go to a server script

--server script

local remotefunction = wherever.it.is
remotefunction.OnServerInvoked = function(Variable1, Variable2)

if Variable1 = false
then
end
end

Basically, how do you send variables over with InvokeServer and OnServerInvoked.

All I need is a small and simple example. My brain is big but not big enough to understand the small example on the wiki

1 comment

1

Yes you can send variables through remote functions. Also it is OnServerInvoke, not OnServerInvoked

2 answers

✓ Accepted answer

You do have a basic idea of how it works but there's some small details missing.

Localscript:

RemoteFunction:InvokeServer(var1, var2)

Server script:

RemoteFunction.OnServerInvoke = function(player, var1, var2)

Note that the OnServerInvoke always automatically passes the player. This is so you know who fired the remote function. The exact same idea also applies to remote events.

1 comment

0

I appreciate the example. Short and simple, just what I needed.

--In a Script
local remotefunction = insert_remote_function_here

game.Players.PlayerAdded:Connect(function(plr)
	local x = remotefunction:InvokeClient(plr, true) --Invokes the joining player's client
	print(x)
end)
--In a localscript
local remotefunction = insert_remote_function_here

remotefunction.OnServerInvoke:Connect(function(example_bool) --The client was invoked by server
	if example_bool == true then
		return "you rang?" --returns a string
	end
end)

1 comment

0

great example. you put effort into this, but it should be OnClientInvoke on the local script, right? Nonetheless good job. Both answers are great answers.

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