generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Need some help understanding RemoteFunctions.

Previous Thread :: Next Thread 
Spirographic is not online. Spirographic
Joined: 17 Aug 2007
Total Posts: 19084
16 Aug 2014 05:22 AM
Sorry if this sounds a little scatterbrained and if I'm missing something obvious here. I just spent the last few hours coding at 3AM ahah

Anyway, I guess what I'm trying to do here is hook up a Click Detector to a RemoteFunction on the client and pass along some arguments. Seems simple enough, but what I don't understand is how you like get the information on what player the RemoteFunction is in.
I'm also having trouble passing the arguments along for some reason, and understanding what all gets passed along, like if there's anything extra like with passing from the client to the server, and what all is different about it, et cetera.

ily bae <33
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
16 Aug 2014 05:39 AM
If a client uses InvokeServer(), the Player argument gets added as the first argument automatically, and the rest of the arguments thereafter. Since that has to be done from a LocalScript, the player argument will _always_ be there. BUT, if using InvokeClient from a server script, you need to specify the player as the first argument instead. This will be the player that recieves the callback (triggers the remote function). I hope that's what you asked for, if not, just reply to this thread and I'll answer.

~The herp lerped a derp~
Report Abuse
Spirographic is not online. Spirographic
Joined: 17 Aug 2007
Total Posts: 19084
16 Aug 2014 05:48 AM
So the first argument I use to invoke the client needs to be the player object inside of game.Players, and from then on, I can use the rest of it for whatever I happen to need, in the localscript, such as strings, tables, et cetera, right?

Assuming all of that is correct, how does the script on the client go about retrieving the information? Would it just be like this?

function RemoteFunction.OnClientInvoke(player,argument,argument,etcetera)

Or is the player argument disposed of once the server is done with it?

ily bae <33
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
16 Aug 2014 06:06 AM
It's much like regular functions, with the only exception that the Player argument (player instance in game.Players, yep) is needed to determine who the callback gets fired for (using InvokeClient()) or which player called it (using InvokeServer()). Here's an example of what InvokeServer

-- In server script:
local RemoteFunction = wherever
function RemoteFunction.OnServerInvoke(Player, ...)
print(Player.Name.." says "..table.concat({...}, ", "))
-- This would print all the arguments passed, including player
end

-- In a LocalScript:
local RemoteFunction = wherever
RemoteFunction:InvokeServer("Hello", "world!")

Same thing goes the other way around, except you need the Player argument when using InvokeClient(). This is essentially the same thing:

-- In server script:
local RemoteFunction = wherever
RemoteFunction:InvokeClient(game.Players.Player1, "Hello", "world!")

-- In a LocalScript:
local RemoteFunction = wherever
function RemoteFunction.OnServerInvoke(...)
print("The server just said "..table.concat({...}, ", "))
end

There might be some errors in this, as I haven't tested it and just wrote it up on the spot. But the callbacks and player arguments and such should be placed correctly.

~The herp lerped a derp~
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
16 Aug 2014 06:07 AM
Woops, managed to accidentally hit the Post button before I was done.
That was pretty much it anyway. Hope everything is clear now, if not, just ask more :P

~The herp lerped a derp~
Report Abuse
Spirographic is not online. Spirographic
Joined: 17 Aug 2007
Total Posts: 19084
16 Aug 2014 07:15 AM
So, here's a rather interesting problem.

I call the RemoteFunction on the server, as expected, like so.

choice=train:InvokeClient(player,1,"This is a string.","Option One","Option Two")

All of the arguments are inputted as expected, like so.

function dialogTrain.OnClientInvoke(type,str,opt1,opt2)

type is expected as an integer, str is expected as a string, opt1 and opt2 are expected as strings, but neither are necessary.

Yet for some reason, at the point in the code where the options are supposed to appear, an error arises in the server script saying that a string is expected on the line calling the function. It doesn't specify anything beyond "string expected."

Is this because I am trying to return an integer? I wouldn't imagine that to be the problem, especially since nothing has been returned yet.

ily bae <33
Report Abuse
Spirographic is not online. Spirographic
Joined: 17 Aug 2007
Total Posts: 19084
16 Aug 2014 07:19 AM
Never mind, I figured it out. Made a capitalization error on the client script. It's all working fine now, it'd seem.

I don't get why it returned an error on the server script, but whatever, false alarm.

ily bae <33
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
16 Aug 2014 07:20 AM
If it errors at the InvokeClient() line, the problem actually lies within the function on the client and not the server, much like calling a normal function, and it prints the call line when it errors. If a string was expected, it might be some kind of concatenation problem, eg. trying to make something that is not a string into a string.
Could you post the client function? :P

~The herp lerped a derp~
Report Abuse
filiptibell is not online. filiptibell
Joined: 10 Mar 2013
Total Posts: 2362
16 Aug 2014 07:20 AM
I see. Glad you were able to solve it!

~The herp lerped a derp~
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image