Player leaving during remote call causes game to stop

While this might work, it’s only a bandaid fix to a player leaving/not returning anything. The fix to the root problem is to not use one in this case.

1 Like

While there’s truth to what you’re saying, I don’t think I would consider it the one and only solution to the problem.

I can’t say I fully understand your hatred for RemoteFunctions and InvokeServer. They are used widely across several major titles on the site and have no negative when used correctly.

I believe thre is misinterpretation going on here.

Invoke server is NOT bad. Invoke client and on client invoke are bad. Remote functions are not bad. Half of them, at least

1 Like

How can I wait for the response then?

ChoosePlayers:FireClient(Sensei, Settings.ACTIVE_PLAYERS)

ChoosePlayers.OnServerEvent:Connect(function(chosenPlayers)
    if #chosenPlayers == 2 then

    else

    end
end

As exploiter could once again just not fire the event back?

1 Like

That is true, it’s a lose-lose situation. You can do a timeout for the event though.

1 Like

Could you provide me with some links on this? Or just a further explanation?

I’m willing to learn here but I’m just unsure if I agree with you.

How tho???

Using this. But instead, of rbxutility, you would swap it out with a BindableEvent.

@ImFarley um sure but what exactly are you looking for.

2 Likes

Seems a little excessive for what I’m trying to do…

No not really, since roblox doesn’t have like a timeout argument for :Wait for events (maybe not yet), this is what we can use for now.

Oh and I modernized this because I actually needed to use it, if you want here is the code

Timeout for event
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

You can make it into a module script so you can use it anywhere in any script.

3 Likes

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