This is a pretty basic question, I’m just asking if it’s possible to wait until you receive anything from the remotefunction you invoke.
Example:
(Client Side)
local rem = script.Parent.RemoteFunction
rem.OnClientInvoke = function()
wait(3)
return "Pie"
end)
(Server Side)
local rem = script.Parent.RemoteFunction
local message = rem:InvokeClient(player)
repeat task.wait(1) until message == "Pie"
print("Received Message", message)
An OnClientInvoke event is fired when the RemoteFunction:InvokeClient function is called from a server script.
repeat wait() until message
print("Received Message", message)
You can call the function named “wait” with no arguments to yield until a message has been received.
Also the variable named “message” can be evaluated as a boolean expression itself, you don’t need to check if it’s a string value equal to “Pie”.
Simple remote functions yield the code from running until a response comes from the other side (which is client here). and if you know what exploiting is, you would know that an exploiter can easily add wait(math.huge) or simply deleting the onClientInvoke function resulting in server yielding forever.
I could use 2 remote events but that’s no different than using a remote function, since you’ll infinitely wait until the 2nd remote event gives you the message.
I guess I’ll just not yield anything from the client since that’s basically what you’re telling me to do. Aren’t there any other ways to prevent exploiters from doing the whole wait(math.huge) though?
instead of waiting infinitely for the 2nd remote use a bool value
local responseGiven = script.BoolValue
local waitTime = 15--seconds to wait until a response(which is the 2nd remote)
--you might want to make the number a bit high as the client might be laggy, so you should get clients ping as well.
local passedTime = 0
repeat
task.wait(1)
passedTime += 1
until responseGiven.Value == true or passedTime > waitTime
responseGiven.Value = false
--do the rest
next part of the script i wrote is(thought might be confusing by itself)
local clientResponse = ReplicatedStorage:WaitForChild("ClientResponse")
local function onClientResponse(plr)
responseGiven.Value = true
end
clientResponse.OnServerEvent:Connect(onClientResponse)
What I did eventually was use remote function from client to server, and using remote events with timeout to mimic a remote functions from server to client