I had a game I worked for a while and I decided to make a shop for it. After triggering a proximity prompt the script would invoke the client who triggered it, and the localscript inside the shop GUI would bring up the gui itself. But suddenly it stopped working. :InvokeClient() no longer works.
When i close the game There is this message in the output:
Player Dun_FB disconnected during remote call to ReplicatedStorage.ShopEvent
This bug works in both robloxstudio and robloxclient.
I cant post in bug reports and i didnt really have anything except for this category sorry about that
A server should rarely invoke a client via RemoteFunction:InvokeClient() as it can be potentially game breaking. For client-only actions that don’t require a callback, like updating a GUI, a server-to-client remote event should be used instead. If RemoteFunction:InvokeClient() is used, risks include:
If the client throws an error, the server will throw the error too.
First of all, I heavily agree with what @SomeFedoraGuy said about using RemoteEvents instead of RemoteFunctions.
Secondly, your original screenshots use :InvokeClient() on the server, but .OnClientEvent on the client. If you were to use RemoteFunctions, then both of these should be Invokes, so the local script should be using .OnClientInvoke instead. But again, I advise against using RemoteFunctions in this scenario. And in your later screenshots, you corrected this inconsistency by changing :InvokeClient() to FireClient().
Lastly, assuming you are using the code in your latest screenshot and there’s no errors outside of the posted code preventing the rest of the code from running, there’s two potential issues I see here:
Make sure ShopEvent is a RemoteEvent,not a RemoteFunction. FireClient uses RemoteEvents. InvokeClient uses RemoteFunctions.
Players do not always have everything loaded in immediately. Due to this, in local scripts, sometimes you need to wait for things to exist. This could be happening with your ShopEvent remote. To fix this, simply change line 139 in your last screenshot to ReplicatedStorage:WaitForChild("ShopEvent") instead of just ReplicatedStorage.ShopEvent.
why don’t you just connect the local script to the proximity prompt when triggered bring up the UI. Instead of the server script you have now that then fires back to the client else you could just use the server script find the ui in the player and make it visible run your setup code on the Getpropertychanged signal for visible
there are only a few times you really need to use remotefunctions and you don’t always have to use remote events you can use attributes and propertychanges even tags are very useful instead of remote events
Thank you for the explanation, ShopEvent is indeed a remoteevent. I think an error would already pop up in the output if there was something wrong.
But I did do what you said anyway, Both of the scripts wait for shopevent but still local script doesnt connect the clientevent from shopevent.
What i am curious about is why this used to work and why is it not working anymore
Edit: By the way, it was not .OnClientEvent(), i took that screenshot after doing what TheTravellerChicken1 recommended me to do.
Plus, thats not even the problem. The problem was :InvokeClient() stopping working without me doing any change on the script.
Also, I have an older version of the game in a different place with the :InvokeClient() function. It still works there but not in this game. Maybe it is also related to games in some way?