Help with waiting a remote event to return

so basically i need help with a script, i fire all the clients and want to wait until they fire the server again, but there should be a maximum time

2 Likes

You should look into RemoteFunctions instead, they are meant for this.

2 Likes

We can simply use OnServerEvent:Wait(). Can’t use a RemoteFunction on all clients at once, now can we?

1 Like

Please review documentation before posting it. This is a very misleading suggestion. RemoteFunctions are perfect for Client > Server > Client but not vise versa. They leave the server exposed to the client’s decision to respond back.

1 Like

I understand this, and I’ve read the documentation. I am aware of the risks and was giving OP this information because it’s what he asked for.

I am not “misleading him”.

Your solution is incorrect anyway. OP wants to yield until all the clients reply back.

You can only ever have one client on the function, so you’re gonna have to sequentially wait for every client which is well, undesirable. Uh, correct me if I’m wrong. misinformation oops

1 Like

The problem with that is not all clients may reply back, so you’re going to always run into issues with unreliability. Expecting everyone in a server to reply back isn’t efficient, there’s definitely a better way to do it than this.

@FurukanDev Why do you need to fire all the clients and wait until they fire back?

An example would be the server waiting for all players to be ready before initiating a game or so. The maximum time is there to force the game to start if not all players answered. Perhaps that? Idk.

That said, while a RemoteFunction would work in this case, it’s just slower than using a RemoteEvent for the same purpose.

This is also untrue, because RemoteFunctions were specifically designed for callbacks like this.

This could be a case of an XY problem, where OP is trying to solve a problem by doing X, but in reality it’s not practical and Y is better.

The documentation warns against using RemoteFunctions for the client, but I provided it anyways because it’s what he requested. I wouldn’t use this method though and I know there’s mostly likely a better way.

1 Like

Let’s just wait to hear the OP for their actual problem.

i thinked a lot on this and tried something like this

local values = {}
		
		
for _, v in ipairs(module.getPlayerCount()) do
	local corona = coroutine.create(function()
	    local func = Start:FireClient(v, map, module.GetRandom(wordCount))
	    table.insert(values, func)
    end)
		
	coroutine.resume(corona)	
end
		
		

now i want to run a function when something get inserted into the table

You didn’t answer the question, I wanted to know why you need to do this, it seems inefficient.

i am making a game based on gui and it will run local and i need to see who will finish first