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: Remote Function help! (advanced!)

Previous Thread :: Next Thread 
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
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 is not online. Mr_Crunch
Joined: 16 Jul 2016
Total Posts: 275
12 Jul 2017 07:24 PM
OnClientEvent, not OnClientInvoke
Report Abuse
Mr_Crunch is not online. Mr_Crunch
Joined: 16 Jul 2016
Total Posts: 275
12 Jul 2017 07:25 PM
& its FireClient
Report Abuse
Mr_Crunch is not online. 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
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
12 Jul 2017 07:27 PM
That's for Remote Events, this is remote functions


r+
Report Abuse
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
12 Jul 2017 07:28 PM
Sorry typo ;3


r+
Report Abuse
ExtremeBuilder15 is online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 3176
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
ExtremeBuilder15 is online. ExtremeBuilder15
Joined: 01 May 2012
Total Posts: 3176
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
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
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
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
12 Jul 2017 08:43 PM
b1


r+
Report Abuse
Tunicus is online. Tunicus
Joined: 16 Feb 2013
Total Posts: 3165
12 Jul 2017 08:50 PM
RemoteFunctions use functions, not events.

RemoteFunction.OnClientInvoke = Function
Report Abuse
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
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
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
12 Jul 2017 09:25 PM
The return is in the click event's function, not the RemoteFunction's callback.


Report Abuse
Tunicus is online. 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
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
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
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
12 Jul 2017 10:17 PM
b2


r+
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
12 Jul 2017 10:42 PM
Remove the ()


Report Abuse
AyeeAndrxw is not online. AyeeAndrxw
Joined: 21 Sep 2015
Total Posts: 291
12 Jul 2017 10:52 PM
Thanks, don't know why I had to do that!


r+
Report Abuse
Disillusions is not online. Disillusions
Joined: 10 Jul 2011
Total Posts: 6365
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
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