You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to Have the client ask the server something, then the server reply, then the client reply, and then the server will send the final result.
What is the issue? Include screenshots / videos if possible!
Not sure how to do this, no similar issues
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Tried doing thing but It didnât work
âclient
function RequestChangeData(action,Variable,Value)
--the server sends 2 numbers then the client uses a formula to combine them then the server checks if the client used it correctly
game.ReplicatedStorage.RemoteFunction:InvokeServer()
local SecurityKey0,SecurityKey1 = game.ReplicatedStorage.RemoteFunction:Wait()
local result = game.ReplicatedStorage.RemoteFunction:InvokeServer(action,"TutorialCompleted", false, (SecurityKey0/23 * SecurityKey1*34)*3/4 + 43)
return result
end
RequestChangeData(1,âTutorialCompletedâ,false) â delete to make it work normally.
âServer
local queuedPlayers = {}
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function(Player,Action,variable,Value,Vefify)
if queuedPlayers[Player.UserId] then
if ((queuedPlayers[Player.UserId][1]/23 * queuedPlayers[Player.UserId][2]*34)*3/4 + 43) == Vefify then
if Action == 1 then
PlayerDataModule.setData(Player, variable, Player.UserId * 3213.895)
local Result = PlayerDataModule.getData(Player)
PlayerDataModule.setData(Player, variable, Value)
return(0)
elseif Action == 2 then
local Result
Result = PlayerDataModule.getData(Player)
return(Result)
end
end
else
local key1 =math.abs(math.random(0,10000))
local key2 = math.abs(math.random(0,10000))
game.ReplicatedStorage.RemoteFunction:InvokeClient(Player,key1, key2)
local tablesec = {key1,key2}
queuedPlayers[Player.UserId] = tablesec
end
Iâm not aware of any method to get a remote function to âwaitâ, in the way youâre asking, they have to return a value and each firing would start a separate thread.
It would also be unsafe to wait in case the client never responds, as this would leave the thread waiting indefinitely.
You can have a table to record the values set in the same scope as the listeners which will allow them to share data between the different remote function threads. You could also keep a timestamp with the data and check this to provide a timeout.
(I would have to test the code, but donât have time right now)
The best way I can think of to approach your question is just to have your code handling the function yield with a task.wait loop and set a variable to the clientâs reply- which the task.wait loop will check- when received.
I had a think and came up with a third option which allows the first remote function to wait for a reply from the client, (I amended my first post).
Itâs not ideal as if the client disconnects the thread could error, so you may need to wrap the RF in a pcall and handle accordingly.