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 Values Client to Server? RemoteFunctions?

Previous Thread :: Next Thread 
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
04 Apr 2016 03:32 PM
How do you pass a variable value to a ServerScript with FilteringEnabled set to true?
I've been trying to do this with RemoteFunctions.

This is what I've been trying so far:

--Server script

Function.OnServerInvoke:connect(function(Player, Color)

--my code

end)

--Local Script

game.Workspace.CreateTag.RemoteFunction:InvokeServer(Player, "Bright red")

What am I doing wrong?
How can I do this?

Any help or advise would be greatly appreciated.
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
04 Apr 2016 03:37 PM
Dammit for the love of god why won't you use remote events? Probably just to piss me off

--server script
local re = game.ReplicatedStorage:WaitForChild("RemoteEvent")

re.OnServerEvent:connect(function(plr,color)
workspace.Part.BrickColor = color
end)

--local script
local re = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local color = BrickColor.new("Bright red")

re:FireServer(color)


Report Abuse
DevConsole is not online. DevConsole
Joined: 02 Jun 2008
Total Posts: 460
04 Apr 2016 03:38 PM
game.Workspace.CreateTag.RemoteFunction:InvokeServer("Bright red")

the client which invoked the server is passed as the first argument to the server automatically whether you pass it from the client or not. You inadvertently made player and color be player.


Report Abuse
DevConsole is not online. DevConsole
Joined: 02 Jun 2008
Total Posts: 460
04 Apr 2016 03:40 PM
Also Tick is right, RemoteEvent is the proper thing to use here, otherwise you're yielding your LocalScript waiting for the color of the brick to be changed by the server, unless you absolutely need to wait for the color to change before executing the reset of the LocalScript code.


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
04 Apr 2016 03:44 PM
@Dev THANK YOU


Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
04 Apr 2016 04:13 PM
Thanks TimeTicks and DevConsole.

I initially took your advise TimeTicks and tried using RemoteEvents, but they didn't work.
Also, sorry if I annoyed you. It was unintentional.

I've tried them again so that I can tell you guys what went wrong.
Here's the code:

--Local script
game.Workspace.CreateTag.RemoteEvent:InvokeServer(Player, "Bright red")

--Server script
Function.OnServerEvent:connect(function(Player, Type)
if Type == ("Bright red") then
print("RE")
ColorMagic(Player)

elseif Type == ("Sea green") then
print("RE2")
ColorMagic(Player)
end
print("in")
end)

"In" is printed but RE or RE2 is never printed.
Why is this?
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
04 Apr 2016 04:33 PM
Can you only pass one argument by any chance?
Report Abuse
DevConsole is not online. DevConsole
Joined: 02 Jun 2008
Total Posts: 460
04 Apr 2016 04:36 PM
you repeated your initial mistake :P

change game.Workspace.CreateTag.RemoteEvent:InvokeServer(Player, "Bright red")
to game.Workspace.CreateTag.RemoteEvent:InvokeServer("Bright red")

you can pass multiple arguments but you're including player as the first argument but as I said previously you dont need to do that because it gets passed in as the first argument automatically by the RemoteEvent/RemoteFunction.


Report Abuse
DivinePheonix is not online. DivinePheonix
Joined: 30 Mar 2011
Total Posts: 11190
04 Apr 2016 04:38 PM
Problem you have here is that you don't need to identify the Player as an argument, the server can tell who sent the request.

When you're debugging I would recommend you print out your parameters instead of random strings so you can identify potential bugs.


game.Workspace.CreateTag.RemoteEvent:InvokeServer("Bright red")
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
04 Apr 2016 04:49 PM
Thanks DevConsole and DevinePhoenix

Is this what I should be doing in that case?

--server

Player = Function.OnServerEvent:connect(function(Type)
if Type == ("Bright red") then
print("RE")
ColorMagic(Player)

elseif Type == ("Sea green") then
print("RE2")
ColorMagic(Player)
end
print("in")
end)

--local

game.Workspace.CreateTag.RemoteEvent:InvokeServer("Bright red")
Report Abuse
DevConsole is not online. DevConsole
Joined: 02 Jun 2008
Total Posts: 460
04 Apr 2016 04:58 PM
--server

Function.OnServerEvent:connect(function(_,Type) -- this will work assuming you set a variable named Function to the RemoteEvent
if Type == ("Bright red") then
print("RE")
ColorMagic(Player)

elseif Type == ("Sea green") then
print("RE2")
ColorMagic(Player)
end
print("in")
end)


Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
04 Apr 2016 05:28 PM
I replaced ColorMagic(Player) with CreateMagic(_) and I get the warning::
"Placeholder value is used here. Consider changing to variable."

Is there any way of turning this into a variable?
I'm just thinking about efficiency here.

Regardless of this, the code seems to be working.
Thanks very much for the help.
Report Abuse
DevConsole is not online. DevConsole
Joined: 02 Jun 2008
Total Posts: 460
04 Apr 2016 05:37 PM
You can change _ to something else if you want, I initially did it because I didn't notice it was used at all in the function and intended it to be just that - a place holder. It's just warning you because it knows _ is a placeholder. It won't affect the performance in any way though.


Report Abuse
cnt_killme is not online. cnt_killme
Joined: 30 Mar 2016
Total Posts: 29
04 Apr 2016 05:41 PM
I highly *highly* suggest you use RemoteEvents.

And change

game.Workspace.CreateTag.RemoteFunction:InvokeServer(Player, "Bright red")


to game.Workspace.CreateTag.RemoteFunction:InvokeServer("Bright red")




~step aside, for the genius cntkillme is here.
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