:InvokeServer() Not Being Detected

Both have this issue.
I have got a work-around, but I’d prefer using the method I’m using here, so a solution is still required.

It looks like you’re shooting for a single remote architecture, and listening to this one remote function/event from multiple scripts.

I suspect your problem is you are binding OnServerInvoke in multiple scripts. If you do this, the most recent binding will always overwrite the previous one. You need to connect this in only one place and then distribute the signal another way.

3 Likes

Does this apply to Bindable Instances as well?
Your post is certainly correct and it would explain why it was working under a different architecture.

Oh, so thats why people create multiple Remote Instances.

This applies to RemoteFunctions and BindableFunctions. OnServerInvoke and OnInvoke are set like function callbacks. They are expected to return a single result, so only a single function can be hooked up to them.

OnServerEvent and OnEvent of RemoteEvents and BindableEvents are events, and like any other event of any other instance these can be listened to from multiple places.

3 Likes

@boatbomber, your long awaited ping (28 mins).

1 Like

It’s also been said by Arseny (I think) that it’s better to have multiple remotes because you’ll actually lower your bandwidth usage since you won’t be using an extra parameter to pass what thing you want it to do. Rather than be using bandwidth to send “GetAsset”, the Remote is named GetAsset and will always do just that.

1 Like

Just split your remotes. I don’t know what kind of convention you’re using but I don’t involve the server with any part of ReplicatedFirst. I keep that service reserved for initial client workings and bootstrapping. If the server needs to get involved at any point, it doesn’t belong in ReplicatedFirst, which then I pass the task to my StarterPlayerScripts strapper.

Alternatively, I just slap a black screen out from ReplicatedFirst as the initialisation step and wait for my processes to finish, then I start up the actual “loading screen” when the server is able to serve the client. Typically these processes include:

  • Preloading assets
  • Waiting for game.Loaded to fire
  • Setting CoreGui enabled states
  • Other must-do-at-start tasks

Otherwise, Defaultio has you there in that you’re overwriting the invocation case for your RemoteFunction. Remember that writable callbacks only take one value. If you’re familiar with ProcessReceipt, this same convention is followed; you can only set it from one script and all others will overwrite it.

This aside, some things I want to comment on.

The child here is available when the top parent is. As for the folder itself, if it doesn’t replicate within 10 seconds, it’ll throw. I suggest not using a yield condition here and not assuming the return value of WaitForChild will be truthy.

RunService.IsStudio. Relying on CreatorId being 0 is a bad dependency that could change. It may already return non-zero values. It isn’t documented, that much is for sure.

PlayerGui needs WaitForChild. PlayerGui is not created immediately under the player when they enter the server.

This isn’t going to give you an accurate report of an error that’s occurring. The script location doesn’t matter, it’ll be constant every time. Instead, pass information about the asset, such as what name was queried.

It should also be noted that if your asset doesn’t exist, your server will permanently hang. You don’t have a catching return condition or a handler for it. When you invoke a function, it expects a return and will yield until one is given. Consider adding a catch return that will run if, by the end of the code’s running, nothing comes back.

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
    return nil -- Catcher return I spoke about
end
1 Like