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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
| |
|
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
|
  |
| Joined: 24 Jun 2011 |
| Total Posts: 1451 |
|
|
| 04 Apr 2016 04:33 PM |
| Can you only pass one argument by any chance? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|