Hi, I am using RemoteFunction:InvokeClient() but the server doesnt wait for the answer of the client and directly sets my variable as nil.
Here’s the code :
You’re being returned nil because the client-side function does not contain instructions to return anything, as the return statements are inside of anonymous functions that you are connecting to MouseButton1Click events. However, that issue is dwarfed by the fact that this is a terrible way of scripting your UI.
First off, you are invoking the client. This is dangerous as an exploiter could simply force your client-side script to yield permanently, effectively disabling it.
Second, you are only connecting the buttons to functions once the server-side script runs, and you are connecting them every single time said script runs, which will lead to unintended behaviour and could be a memory leak.
You are validating action == "IslandPurchase" on the client; this should be done on the server, and you are using pcall when it’s not necessary as you can be guaranteed a response.
Finally, you are returning strings. This isn’t necessarily an issue unless you are doing any logic with the return, in which case you’ll have magic strings involved which are dangerous.
At a higher level, your approach to the purchasing interaction is flawed. This is what your code is aiming for: