I have a LocalScript, that when a player clicks a button, it fires an event to the server to check if the player has the item unlocked. The server then fires back to that client whether they have it or not. The problem I’m having with this is there’s a delay, about 1 second. Is there a way to instantaneously check something from client-server, server-client?
I’ve been told previously to do the checking inside a server script, to prevent people hacking, so that’s why I’m checking if they have the item in a server script (uses datastores as well)
Check on the server only when you need to - instead of checking on the server whether a player owns an item when they press the button, check it beforehand, save it on the client, and use that in the future for faster feedback.
Additionally, don’t check it on the server when the player presses the button, check it when the server goes over the request from the client to use the item.
Having instant feedback is important, so you are allowed to maybe do some insecure stuff on the client as long as the server still validates everything.
Also, you shouldn’t be making DataStore requests every time someone presses a button. Load a player’s data once, save it to a table for later usage, then modify that table when you need to change the player’s data. DataStores should be seen as a limited way to store information permanently, not a way to generally manage player information.
Is there a way to do it using tables? Because I have a lot of different guns, and it would be a pain firing it all the time to check if they have said item. As well as when a player buys an item, it’d have to change to say it’s owned
The bottleneck here should be your internet connection and the network rate between Roblox clients and server (20hrz is the fastest I believe).
Any server-side validation is going to take a bit of time. But shouldn’t take a whole second. Still might be a noticeable delay to the user though. That’s just the trade-off.
People hide this a bit by adding client-side effects, such as the button animating in some way.
Your method of server-side checking is correct though.
I’d use a RemoteFunction and invoke the server what I want the check, let the server verify everything is correct, and use return on the server as you can return results to the client from the server with RemoteFunctions.
Mm, you could. If all of your weapons had an ID, you could do one massive get request and the server could send you a table containing the ID of every gun you own.
You could also do the same on the server, and have a table containing the ID of every weapon the player owns. This table is what would get saved and loaded.
All you need to do to add/remove weapons is add/remove entries from the table.
I would assign id’s to each weapon, when a player logs in, give all clients a copy of their list of owned weapon id’s , when the player leaves, remove that list from all other clients, update the data for all clients each time a player gains or looses a weapon.
That way, each client should know which weapons the other clients own.
Its a bit more memory on the client, holding a table of id’s for each other client, but as is so often the case in programming, you trade memory size for speed, and vice versa.