:InvokeServer() Not Being Detected

Good day all,

The Problem
I have a “Player Manager (client)” script placed in ReplicatedFirst which performs some basic functionality immediately after a player joins the game, namely moving the custom “Loading Menu” into the player’s PlayerGui.

This is where things become slightly more convoluted. The Player Manager (Client) script receives the Loading Menu from another script on the server side, called “Asset Manager”. The Asset Manager’s job is to take incoming asset requests (all assets are stored in ServerStorage.Assets) and return a clone of the requested asset by way of a RemoteFunction.

In this case, the Player Manager (Client) script is attempting to request the Loading Menu by firing a RemoteFunction. Most of the time it works, however, approximately 1-in-3 times this will, at random, not work and I will get an “attempting to index nil value” error.

What I Know So Far
When the error occurs:
• The Asset Manager script does not detect the :InvokeServer().
• The server has just started.
• It can occur even after a 10-second wait() period.

The issue may be:
• The Asset Manager script has not loaded by this point. (I’ve tested this and it does connect the events before the error appears)

Player Manager (Client)

-- << VARIABLES >> --
local Players 			= game:GetService("Players")
local ReplicatedFirst	= game:GetService("ReplicatedFirst")
local ReplicatedStorage	= game:GetService("ReplicatedStorage")
local Workspace			= game:GetService("Workspace")

local RemoteFunction = ReplicatedStorage:WaitForChild("Remote Instances", 10):WaitForChild("Remote Function", 10)

local Studio = game.CreatorId == 0
local Player = Players.LocalPlayer



-- << FUNCTIONS >> --
function LoadGame ()
	-- fetch loading menu
	local LoadingMenu = RemoteFunction:InvokeServer ("Fetch Asset", "Loading Menu")
	-- display loading menu
	LoadingMenu.Parent = Player.PlayerGui
	-- remove loading screen
	ReplicatedFirst:RemoveDefaultLoadingScreen()
end



-- << EXECUTION >> --
LoadGame ()

Asset Manager

-- << VARIABLES >> --
local ReplicatedStorage		= game:GetService("ReplicatedStorage")
local ServerScriptService	= game:GetService("ServerScriptService")
local ServerStorage		    = game:GetService("ServerStorage")

local BindableEvent	    = ServerStorage["Bindable Instances"]["Bindable Event"]
local BindableFunction	= ServerStorage["Bindable Instances"]["Bindable Function"]
local RemoteFunction	= ReplicatedStorage["Remote Instances"]["Remote Function"]

local Assets = ServerStorage["Assets"]



-- << FUNCTIONS >> --
function SearchForAsset (Player, Function, Asset)
	-- verify request is relevant
	if Function == "Fetch Asset" then
		-- search for asset
		if Assets["User Interfaces"]:FindFirstChild(Asset)  then
			-- fetch asset
			local Asset = Assets["User Interfaces"]:WaitForChild(Asset, 5)
			return FetchAsset (Asset)
		else
			-- report non-existent asset
			BindableEvent:Fire ("Report Error", "Asset '".. Asset .."' doesn't exist. Error Location: ".. script:GetFullName())
		end
	end
end

function FetchAsset (Asset)
	-- create cloned asset
	local Asset = Asset:Clone()
	Asset.Parent = ReplicatedStorage.Assets
	-- send cloned asset
	return Asset
end



-- << EXECUTION >> --
BindableFunction.OnInvoke 	  = SearchForAsset
RemoteFunction.OnServerInvoke = SearchForAsset

Can you try printing something right before the client invokes it, the start of the servers function, and can you print the reply of the server?

Upon further investigation, it would appear that in the tests which are encountering this issue, even using a while loop, it is incapable of detecting the :InvokeServer()

In the LoadGame() function, put a print before and after the line that invokes the RF. Do they both print?

Also, try replacing the connected function in AssetManager with an anonymous function that just prints the players name. Does that fire?

In the LoadGame() function, both prints fire.
In the Asset Manager, the anonymous function doesn’t fire.

That’s the thing, the server doesn’t even detect the invocation and hence doesn’t return anything.

Can you double check that they are both connecting to the same RF? Maybe you have 2 of the same name and they each catch the other one.

All :InvokeClient() functions go through the same remote functions, as seen below.
image
The “Function” argument of all invocations determine what script should react.

Ok, I looked at your script. In the client you pass two arguments, but in the server you only use 1. Also the first argument in the server should be the player by default (this is the case for RE’s and I’m pretty sure it’s the same.)

Uhhh, if you look correctly, I’ve got 3 arguments in my Asset Manager script, and the first one is player.
Additionally, I use both the the arguments. Perhaps you’re looking at “FetchAsset()”.

1 Like

Yeah, he must have misread. Regardless, incorrect arguments wouldn’t stop it from connecting the Invoke.

Sorry, I looked at fetch. Did you print all the arguments at the start of the search function?

We’ve already established that those functions don’t even fire.

Could this be a bug of some description or something?

I don’t remember enough about Lua syntax off the top of my head but you have a space before inputting the arguments on the client side. I can’t imagine that’s the issue but at this point I’m out of ideas

No, that’s not got anything to do with it, I do that for aesthetic purposes and clarity.

Yeah, I figured as much. I’m as stumped as you. We’re definitely missing some glaringly obvious screw up and when someone points it out we’ll all feel like buffoons.

Probably. Only thing I can really think of is that the server is connecting the RF after the client joins, maybe try adding a wait(3) on the client or something?

I’ve tried waiting for 10 seconds as deliberated upon in the original post.

When you post the solution, ping me so I see it. I’m really curious what I missed here.

Are you testing this in studio or in game?