:InvokeClient() on client doesn't work but .OnServerInvoke() does work

I have a remote function that I am invoking on the client side, however, it causes the thread to yield control for an eternity as it doesn’t seems to be returning any values.

On my server side where the .OnServerInvoke is attached, everything runs fine down to the return statement.

Yet nothing is being received on the client side.

Code snippets

-- server side
corst.instance.OnServerInvoke = function(plr: Player)
	print("A")
	-- ...some tasks

	print("B")
	local returnValue = 10
	
	print("C", s)
	return returnValue
end
-- client side
print("1")
local career = instance:InvokeServer()
print("2")

Debugging

Output for serverside shows, "A", "B", "C" 10 (all 3 intermittent print statements).
However, output for clientside shows, "1", it never gets to "2".

instance:GetFullName() manages to print out the full path to the remotefunction instance on the client side.
Same goes for instance.Parent, it is not nil.

Solutions I’ve Tried

Adding task.wait() with a hardcoded value of 5 before invoking the server on the client side seems to work successfully.
Though I do not want to rely on such hacky workarounds that may fail without notice.

Note

My remote instances are wrapped by a class instance (object).
I do have a similar setup where it utilises the same wrapper object on a remote function and that does return successfully, however the only difference is that it is only triggered on player events, so it isn’t immediately after the player loads in.

There is nothing between the :InvokeServer() call and the 2 intermittent print statements.

Closing

I’ve been debugging for days to no avail, the client simply does not want the return value.
Is there something I am overlooking?

Do the tasks involve a call to coroutine.yield and coroutine.resume? If so, that’s the cause of your issue. There was an issue with remote and bindable functions that caused the thread to hang infinitely but it was addressed with the release of the task library. So replace coroutine.resume with task.spawn.

Yep, it does to fetch the server-sided object (in the event of it not being initialised yet).
Thanks for referencing the bug that was completely unknown to me.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.