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

I need to know how remote function works?

Asked by 3 years ago
Edited 3 years ago

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
Yes you can send variables through remote functions. Also it is OnServerInvoke, not OnServerInvoked SilentsReplacement 468 — 3y

2 answers

Log in to vote
5
Answered by 3 years ago

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.

0
I appreciate the example. Short and simple, just what I needed. legoguy939 418 — 3y
Ad
Log in to vote
1
Answered by 3 years ago
Edited 3 years ago
--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)
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. legoguy939 418 — 3y

Answer this question