|
| 12 Jul 2017 07:22 PM |
Can the server create the callback, e.g this is what I have. -- server local response = pcall(RemoteEvent:InvokeClient(player)) print(response)
-- client RemoteEvent.OnClientInvoke:connect(function() Gui.Enabled = true TextButton1.MouseButton1Click:Connect(function() return 'yes' end TextButton2.MouseButton1Click:Connect(function() return 'no' end end)
-- Output 12:22:35.848 - OnClientInvoke is a callback member of RemoteFunction; you can only set the callback value, get is not available 12:22:35.848 - Stack Begin 12:22:35.849 - Script 'Players.AyeeAndrxw.PlayerGui.LocalScript', Line 18 12:22:35.849 - Stack End
r+ |
|
|
| Report Abuse |
|
|
Mr_Crunch
|
  |
| Joined: 16 Jul 2016 |
| Total Posts: 275 |
|
|
| 12 Jul 2017 07:24 PM |
| OnClientEvent, not OnClientInvoke |
|
|
| Report Abuse |
|
|
Mr_Crunch
|
  |
| Joined: 16 Jul 2016 |
| Total Posts: 275 |
|
| |
|
Mr_Crunch
|
  |
| Joined: 16 Jul 2016 |
| Total Posts: 275 |
|
|
| 12 Jul 2017 07:27 PM |
if its a remotefunction why does it say RemoteEvent lmao confused me..
anyways you have it wrong..
function RemoteFunction.OnClientInvoke()
end |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2017 07:27 PM |
That's for Remote Events, this is remote functions
r+ |
|
|
| Report Abuse |
|
|
| |
|
|
| 12 Jul 2017 07:30 PM |
| First of all, you have your variable named wrong, you're using a RF but it's named as an RE. --client function yourFunc() Gui.Enabled = true TextButton1.MouseButton1Click:Connect(function() return 'yes' end TextButton2.MouseButton1Click:Connect(function() return 'no' end end RemoteEvent.OnClientInvoke = ######## ################ might want to consider changing the TextButton events so that they're disconnected, I'm not sure if lua garbage collects them. |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2017 07:31 PM |
First of all, you have your variable named wrong, you're using a RF but it's named as an RE.
--client function yourFunc() Gui.Enabled = true TextButton1.MouseButton1Click:Connect(function() return 'yes' end TextButton2.MouseButton1Click:Connect(function() return 'no' end end
RemoteEvent.OnClientInvoke = yourFunc thou might want to consider changing the TextButton events so that they're disconnected, I'm not sure if lua garbage collects them.
|
|
|
| Report Abuse |
|
|
|
| 12 Jul 2017 07:53 PM |
Still won't work.
What happens now is when I return the value it won't print, therefore it is still yielding and when I close the game it prints 'nil'
r+ |
|
|
| Report Abuse |
|
|
| |
|
Tunicus
|
  |
| Joined: 16 Feb 2013 |
| Total Posts: 3165 |
|
|
| 12 Jul 2017 08:50 PM |
RemoteFunctions use functions, not events.
RemoteFunction.OnClientInvoke = Function |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2017 09:18 PM |
Okay, let me redo this post:
For some reason, my GUI won't return a value to my remote function. Here is my script:
-- Server local response = ServerToClient:FireClient(player) print(response)
-- Client
function OpenGui() DataGui.Enabled = true NewSlot.MouseButton1Click:Connect(function() DataGui.Enabled = false return 'No' end) OldSlot.MouseButton1Click:Connect(function() if OldSlot.Text == 'Load Data' then OldSlot.Text = 'Loading Data...' return 'Yes' end end) end
ServerToClient.OnClientInvoke = OpenGui()
Nothing will out-put, meaning it will not return.
r+ |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2017 09:25 PM |
The return is in the click event's function, not the RemoteFunction's callback.
|
|
|
| Report Abuse |
|
|
Tunicus
|
  |
| Joined: 16 Feb 2013 |
| Total Posts: 3165 |
|
|
| 12 Jul 2017 09:26 PM |
Read the API, the proper method is InvokeClient
Also on that bottom line you're supposed to pass the function itself, you're instead running the function and passing the result, either string "yes" or "no". Plus your structure is wrong, return ends the function and the result is passed in its nearest function enclosure. Therefore you're returning "yes" and "no" on the MouseButton1Click functions |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2017 09:36 PM |
Okay, so now here is what I have.
- Server
local response = ServerToClient:InvokeClient(player) if response == 'Yes' then -- does code
- local
local toreturn = nil function OpenGui() DataGui.Enabled = true NewSlot.MouseButton1Click:Connect(function() DataGui.Enabled = false toreturn = 'No' end) OldSlot.MouseButton1Click:Connect(function() if OldSlot.Text == 'Load Data' then OldSlot.Text = 'Loading Data...' toreturn = 'Yes' end end) while toreturn == nil do wait(1) end return toreturn end
ServerToClient.OnClientInvoke = OpenGui()
But the problem is now it will open the gui by it's self and run the function.
r+ |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 12 Jul 2017 10:52 PM |
Thanks, don't know why I had to do that!
r+ |
|
|
| Report Abuse |
|
|
|
| 12 Jul 2017 11:11 PM |
You were calling the function and setting OnClientInvoke to it's return value rather than the function itself
What you were doing (example)
function hi() return 'hello' end
OnClientInvoke = hi()
--equivalent to
OnClientInvoke = 'hello'
What you needed to do
OnClientInvoke = hi --setting it to the function
--equivalent to
OnClientInvoke = function() print 'hello' end
|
|
|
| Report Abuse |
|
|