Player leaving during remote call causes game to stop

How can I incorporate it then?

local function wait_until_timeout(event, timeout)
	if type(timeout) == "number" then
		local signal = Instance.new("BindableEvent")
		local connection 
		connection = event:Connect(function(...)
	    	connection:Disconnect()
	    	signal:Fire(...)
		end)
		
		delay(timeout, function()
	    	if connection then
	        	connection:Disconnect()
	        	connection = nil
	        	signal:Fire()
	    	end
		end)
		return signal.Event:Wait()
	end
	return nil
end

ChoosePlayers:FireClient(Sensei, Settings.ACTIVE_PLAYERS)
ChoosePlayers.OnServerEvent:Connect(function(chosenPlayers)
	if #chosenPlayers == 2 then
    end
end)

The reply I linked showed an example.

local player, chosen_players = wait_until_timeout(remote.OnServerEvent, n)
1 Like

And what happens if it’s returned nil?

if ChosenPlayers then
    if #ChosenPlayers == 2 then
        Setup2Players(true, ChosenPlayers)
    else
        print('No players')
    end
else
    print('No players')				
end

Don’t really wanna run the same code twice (‘No players’)

Just use a different message like, Didn't respond in time.

… Except for the fact that the code is gonna be the same :man_facepalming:

if ChosenPlayers then
if #ChosenPlayers == 2 then
    Setup2Players(true, ChosenPlayers)
else
	-- Get random 2 players if sensei doesn't pick
	for _, player in pairs(Settings.ACTIVE_PLAYERS) do
		if #ChosenPlayers < 2 then
			if player ~= Sensei then
				table.insert(ChosenPlayers, player)
			end
		end
	end
				
	Setup2Players(true, ChosenPlayers)
end
else
	-- Get random 2 players if sensei doesn't pick
	for _, player in pairs(Settings.ACTIVE_PLAYERS) do
		if #ChosenPlayers < 2 then
			if player ~= Sensei then
				table.insert(ChosenPlayers, player)
			end
		end
	end
				
	Setup2Players(true, ChosenPlayers)
end

… Except for the fact that functions exist for the reuse of code :man_facepalming:

1 Like

Why are you using two nested if statements…? Just put both the conditions in one:

if ChosenPlayers and #ChosenPlayers == 2 then

else

end
3 Likes

P.S. supposedly Roblox patched the permanent hang issue as far as exploiters not returning anything goes, but they still have the chance to hang by delaying when the client returns a response.

A couple of posts in regards to it from this thread:

1 Like

So should we still avoid invoke client? I would say yes.

Yes, you still should avoid InvokeClient. If you want any semblance of the server wanting data from the client, you can set up a RemoteEvent and do the “round trip” yourself. It also allows you to expect the client to respond with something in a certain time period before raising suspicions about what its doing.

1 Like