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

how do remote functions act in a variable?

Asked by 3 years ago
Edited 3 years ago

i have a remote function to send and receive a table from client to server, but calling upon this remote function takes a pretty long line of code. how will the remote function act in a local variable? will the remote function only get invoked once? or will it be invoked every time the variable is referenced?

update: i ended up putting the reference line to the remote function into a local function, and having the local function return the returned value from the remote function. this should have it invoke the remote function every time the local function is referenced, right?

0
I can't post an answer yet because I just posted one and am on a cooldown, but the remote function will only be invoked when assigning the variable. Hqsuperlabgames 41 — 3y
0
I can't post an answer yet because I just posted one and am on a cooldown, but the remote function will only be invoked when assigning the variable. Obviously, you will have to return a value in your remote function script for it to assign the variable anything other than nil. Hqsuperlabgames 41 — 3y
0
 Local variables are basically a global. Local functions are functions that run on its own scope. So by your question, the remote function will be invoked every time the variable is referenced, as its not a local function. JesseSong 3916 — 3y
0
variables are quick and can save a lot of time writing code. JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited by appxritixn 3 years ago

The remote function will only be invoked when assigning the variable. You can invoke it again, just by reassigning the variable to the same remote event.

```

-- First time

local variable = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent").FireServer() 

-- Second time

variable = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent").FireServer() 

```

I'm not sure why its not showing up as code.

0
Fixed code formatting appxritixn 2235 — 3y
0
oh okay, thanks! TheDude646 72 — 3y
Ad

Answer this question