|
| 18 Jan 2017 01:21 PM |
Hi I am playing around with remote functions and having trouble passing arguments
what i need to happen is this
Server fires event
Server sends data to client
client receives data
clients then sends back ITS OWN response
The WIKI is very unclear on passing arguments
|
|
|
| Report Abuse |
|
|
iYoshiFox
|
  |
| Joined: 14 Apr 2012 |
| Total Posts: 1058 |
|
|
| 18 Jan 2017 01:27 PM |
-- Client Side
remoteFunction:InvokeServer(arguments)
-- ServerSide
function remoteFunction.OnServerInvoke(client, arguments) end
OnServerInvoke always has a 'client' argument, and all other arguments passed are after the 'client' argument.
Hope I helped ^-^ |
|
|
| Report Abuse |
|
|
TimeTicks
|
  |
| Joined: 27 Apr 2011 |
| Total Posts: 27115 |
|
|
| 18 Jan 2017 01:29 PM |
https://forum.roblox.com/Forum/ShowPost.aspx?PostID=200061209
|
|
|
| Report Abuse |
|
|
|
| 18 Jan 2017 01:50 PM |
Not quite what I need
I need the SERVER To fire a event ALONG with data+
example (I am very aware not real code, I am just visualizing)
Server:FIREALLCLIENTS(DATA)
client:OnEvent(SERVERS_DATA)
client: does code using that data
client: Return diff data
Server: gets the data response, waiting for ALL clients (or time)
then moves on using that data |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2017 01:52 PM |
| never allow the client what data the server needs to save.. |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2017 01:53 PM |
| never allow the client to tell the ser Er what data it needs to save..* |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 18 Jan 2017 01:54 PM |
| He justs wants info from the client lol, you sometimes want the server to know which button the client clicked right? |
|
|
| Report Abuse |
|
|
| |
|
| |
|
|
| 18 Jan 2017 01:58 PM |
@pketny "client: does code using that data
client: Return diff data
Server: gets the data response, waiting for ALL clients (or time)
then moves on using that data"
right there he says the client will return new data to the server to be used in the case that the data is points, levels, or anything of that nature, that is a bad way to do it |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2017 01:59 PM |
I need the server to do this
Send an alert to the client usinging these vars:
Message MessageType color font special
using these vars the client is going to create a GUI with some choices
then depending on what choice the client picks it will send that response to the server
so i guess "yes"
then with that data the server can decide what to do with that client |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2017 02:02 PM |
first create aatable of players in the server, then fireallclients have an event that fires when a player responds, remove that player from the table have a loop that waits until the table is empty |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 18 Jan 2017 02:04 PM |
You want a RemoteFunction instead Make one in the ReplicatedStorage named DataFunction
-- client DataFuncton = game.ReplicatedStorage:WaitForChild("DataFunction")
function DataFunction.OnClientInvoke(data) for _,v in next, data do print(v) end -- just print all the data in the array received return true -- return whatever you'd like, different data, etc end end
-- server local DataFunction = game.ReplicatedStorage:WaitForChild("DataFunction") local oldData = {1,2,3,4,5} -- blah blah, alter at will, put inside the function if you want, too local newData -- the most recent client data
function CollectData() newData = {} for _,player in next,game.Players:GetPlayers() do local response = DataFunction:InvokeClient(player,oldData) table.insert(newData,response) end end
|
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 18 Jan 2017 02:05 PM |
So jsut do this:
Server:FIREALLCLIENTS(DATA):
local playersSendTo = game.Players:GetPlayers() local handled
askQuestion:FireAllClients("What do u like more?", "apple", "pear")
wait(time)
if not handled then ---not all players gave their opinion end
client:OnEvent(SERVERS_DATA) + client: does code using that data + client: Return diff data:
askQuestion.OnClientEvent:connect(function(question, option, option2) answer1 = option answer2 = option2
--Set the right text for the right buttons askingFrame.Visible = true end)
ButtonOption1.MouseButton1Click:connect(function() optionChosen:FireServer(answer1) end
-- same for buttonoption2
Server: gets the data response, waiting for ALL clients (or time)
optionChosen.OnServerEvent:Connect(function(player, option) ---save option --remove player from playersSendTo
if #playersSendTo == 0 then -- all players gave opinions handled = true end
end) |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 18 Jan 2017 02:07 PM |
| Sorry, a bit messy, typed it in a hurry, hope you understand |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2017 02:10 PM |
no it wont use andthing that needs to secure
it is alerting the clients a new round is about to start and asking if they want to join |
|
|
| Report Abuse |
|
|
|
| 18 Jan 2017 02:10 PM |
Wow why i typed that a bunch of replies
|
|
|
| Report Abuse |
|
|
|
| 18 Jan 2017 02:15 PM |
| that makes more sense thanks pt |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 18 Jan 2017 02:52 PM |
Use mine. It is secure if you know what you're doing. Don't need events
|
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 19 Jan 2017 04:20 AM |
@Soybeen my code is a bit messy and is meant to be pseudo like. So it has a lot of flaws, but why would using RemoteFunctions instead of RemoteEvents be more 'Secure'?
Also RemoteFunction:InvokeClient is a YieldFunction, so the players will be invoked 1 by 1 instead of all at them same time |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2017 04:29 AM |
wrap it in a coroutine then
data = {} responded = 0 for i, v in pairs(game.Players:GetChildren()) do coroutine.wrap(function() data[p.Name] = remotefunc:InvokeClient(v,data) responded = responded + 1 end)() end repeat wait() until responded == game.Players.NumPlayers --do stuff with dictionary of data
#code self = nil |
|
|
| Report Abuse |
|
|
|
| 19 Jan 2017 04:32 AM |
NONONONONONONNONOOOOOO Never hide the fact that something is a tuple.
askQuestion.OnClientEvent:connect(function(question, option, option2) answer1 = option answer2 = option2
>>>>
askQuestion.OnClientEvent:connect(function(question, ...) local answers = {...} answer1 = answers[1] answer2 = answers[2] |
|
|
| Report Abuse |
|
|
Wrathsong
|
  |
| Joined: 05 Jul 2012 |
| Total Posts: 22393 |
|
|
| 19 Jan 2017 05:16 AM |
https://www.youtube.com/playlist?list=PLatbVFCcsDB9JZE_1WQvmG0i4NrpNIybs
Ever wanted to learn how to script? Check out my YouTube channel: youtube.com/austintheslayer Want to see me code in action? Follow my twitch: twitch.tv/austinrblx |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 19 Jan 2017 05:31 AM |
cody why would you do "local answers = {...} [local] answer1 = answers[1] [local] answer2 = answers[2]"
It makes no sense having to create a table for no reason when you could have easily just loaded the tuples into the locals directly. |
|
|
| Report Abuse |
|
|