While a function is running, I want the function to wait for a clients input, and that input will then influence the output of the function. To keep things simple, I wrote an example. How would I fix my code below?
--a: some variable
--b: options for client input
--c: client input variable
--In Script
local remoteEvent = Instance.new("RemoteEvent")
local remoteFunction = Instance.new("RemoteFunction")
local function example(a, b)
local c = nil
remoteEvent:FireClient(b)
remoteFunction.OnServerInvoke = function(c)
print(c) --This works!
return c
end
print(a + c)
end
--In local script
remoteEvent:OnClientEvent:Connect(function()
--gets client input from options b
remoteFunction:InvokeServer(c)
end)
Obviously at first I can just use a remote function separately from the function to get client input, and then put it into example() as a third parameter, but for my special case, I need to specifically get client input for the function.
What I do have working is the ability to get c in the onserverinvoke function. I’m not so sure about return c working though.
I also have another problem, print(a+c) doesn’t wait for onserverinvoke. Since the client takes a while to input, the function is too fast and skips right to print(a+c).
Any fixes or alternatives to what I can do? Really just looking for the waitforonserverinvoke() thing I don’t know about.