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 » Scripters
Home Search
 

Re: Passing function to client from server?

Previous Thread :: Next Thread 
InnovatedFighting is not online. InnovatedFighting
Joined: 30 Oct 2014
Total Posts: 1040
25 Jul 2016 05:07 PM
I am trying to pass a function to client from server but I have had some very strange outcomes from it. When testing in single player, it prints the name of the game and then "hello", when I want it to print the name of the player.

When I test in multiplayer(a 2 player test server) it yields an error that says func is nil, which I honestly do not understand why since I am passing the func.

Here is the script -

Server -
game.Workspace.Value.Changed:connect(function(c)--[[In order to control it, I change the value manually to run the function]]
game.ReplicatedStorage.RemoteEvent:FireAllClients(function()
print(script.Parent.Parent.Name) --[[In single player, prints the name of the game]]
end)
local str = "hello"
game.ReplicatedStorage.RemoteEvent:FireAllClients(function()
print(str) --[[In single player, prints "hello"]]
end)
end)

Local -
game.ReplicatedStorage.RemoteEvent.OnClientEvent:connect(function(func)
func()
end)


Report Abuse
BothAngles is not online. BothAngles
Joined: 01 Dec 2011
Total Posts: 9604
25 Jul 2016 05:09 PM
Stop using FE








Permanently
Report Abuse
InnovatedFighting is not online. InnovatedFighting
Joined: 30 Oct 2014
Total Posts: 1040
25 Jul 2016 05:10 PM
I need to use FE though


Report Abuse
keitheroni is not online. keitheroni
Joined: 03 Nov 2010
Total Posts: 6359
25 Jul 2016 05:16 PM
honestly, this is more complicated than it needs to be. i'm pretty sure whatever you're trying to do (idk the context) can be accomplished using a modulescript (while still using fe).


Report Abuse
keitheroni is not online. keitheroni
Joined: 03 Nov 2010
Total Posts: 6359
25 Jul 2016 05:17 PM
"Stop using FE"

why would you recommend this to anyone lol, fe doesn't create any obstacles tbh


Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
25 Jul 2016 05:22 PM
You can't pass functions, as simple as that.
This is a guess and I doubt it's even near the correct answer to why, but there's no reference to the function on the client's side hence it being nil.

print(function() end) might help you understand my guess above.
Report Abuse
InnovatedFighting is not online. InnovatedFighting
Joined: 30 Oct 2014
Total Posts: 1040
25 Jul 2016 05:23 PM
I would like to do this in order to control all Player's GUIs at the same time, and do it on the client side instead of server, to minimize work on server.




Report Abuse
InnovatedFighting is not online. InnovatedFighting
Joined: 30 Oct 2014
Total Posts: 1040
25 Jul 2016 05:25 PM
@ozzy The variable func is defined as a parameter on the client side though?


Report Abuse
InnovatedFighting is not online. InnovatedFighting
Joined: 30 Oct 2014
Total Posts: 1040
25 Jul 2016 05:30 PM
In single player, I would guess that the reason it is printing stuff related to the server script because it is simplifying the script[ie finding out what script.Parent.Parent.Name is]

But I do not get why it thinks func is nil on server side. And you should be able to pass a function like this, but I'll just try and find another way to do what I am aiming for.


Report Abuse
GGGGG14 is not online. GGGGG14
Joined: 29 Jan 2012
Total Posts: 25344
25 Jul 2016 05:33 PM
I don't understand why you would want to pass an entire function from the client-server or vice-versa. There are many other more efficient ways to go about this.

a) Module scripts -- this is their entire purpose; to be required and utilized in all other script types.
b) RemoteEvents -- these should run separate functions in server/client through OnServerEvent & OnClientEvent (so passing a function as an argument is just silly)
c) RemoteFunctions -- same thing as above & returns value
d) A combination of any of the above

Report Abuse
OzzyFin is not online. OzzyFin
Joined: 07 Jun 2011
Total Posts: 3600
25 Jul 2016 05:37 PM
with reference I meant whatever the address of the function is, client does not find anything on that address and the func variable becomes nil
Report Abuse
InnovatedFighting is not online. InnovatedFighting
Joined: 30 Oct 2014
Total Posts: 1040
25 Jul 2016 05:48 PM
The main reason I wanted to do this is so I could access stuff on client side(Like a player's GUI), while using server variables(like which GUI I would want to change), and wanted to try and do this without using more then 1 remoteevent. I also wanted to change all Player's GUIs at the same time and didn't want to use threads.

I realize this is not possible now, and will probably just use separate events/functions in order to do this.

Thanks for the replies.


Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
25 Jul 2016 05:56 PM
You wouldn't be able to do that anyways, it doesn't make sense.


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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