So in terms of scripting the baseline of the inventory, and loading all your items im all good. However when it comes to monitoring changes in the items (in this scenario the amount you own) I’m not entirely confident.
So basically my question is whats the most efficient way to mointor changes in the amount of items you own, my current ideas were as follows:
Connect a function to all of them and disconnect the function when you no longer own any of the items.
Maybe use some sort of signal system to tell the client to update the inventory
Refresh the inventory whenever its opened.
For the sake of the scenario lets say you have 80 different slots in your inventory.
If I’m understanding you correctly, you have it all working on the server, and now you want to update a GUI on the client side to reflect changes to the inventory?
Is this correct, or are you asking something different?
If those “values” are represented with e.g. NumberValue objects, then you can just do something like this on the client:
local inventoryValueFolder = game.ReplicatedStorage:FindFirstChild("InventoryValueFolder")
local screenGui = script.Parent
local cashLabel = screenGui:FindFirstChild("CashLabel", true)
function updateCashLabel()
cashLabel.Text = string.format("Cash: %s$", inventoryValueFolder.Cash.Value)
end
updateCashLabel()
inventoryValueFolder.Cash.Changed:Connect(updateCashLabel)
There isn’t a point to update the player’s inventory unless they requested that themselves. Just update the inventory when they open for example their inventory menu. Have a short animation so that they won’t notice that you’re fetching the data from the server.
That’s a good idea! While their inventory is open though, it might still make sense to listen for changes. Otherwise, their inventory would only update every time it’s re- opened.
I doubt their inventory will change while they are in it, since they are the ones who are controlling it, but yeah. If there are changes while the player has the inventory open the server should notify the client.
This was originally my second choice, In what way would one notify the client that the person has collected an item while the inventory is open, since if you can potentially pick up 30 items in <1 min that could cause remote spam.
You have a bandwidth capacity that you can use! 30 requests per minute isn’t a lot, it’s barely anything!
If you’re talking about 30 requests per second, then you might reconsider but it isn’t spam if you’re updating when it’s needed.
But, something that you also can do instead, is to just add it on the client. Let’s assume that you have an inventory, with 5 balls. When you press “E” on another ball, the client can just add that to the inventory on its own. That way, you don’t have to notify the server, which notifies the client.
This is recommended practice, and is used in most games because it’s good. Players need “instant feedback”, or the game feels broken to them. For example, in Phantom Forces (that I’m playing right now), when you shoot someone, you don’t wait for the server to “approve” that you shot the player, the client does its own “calculations” to see if the bullet hit the other player. If it did, you get a hitmark.
EDIT: You still have to make sure it was a valid action on the server, but you can do it on the client nonetheless.
This is good for making games feel responsive, but for serious projects should be coupled with a server- side “sanity check” to foil simple attempts at cheating. These checks might end up using as much bandwidth as the original solution.
No matter what, I wouldn’t start fixing these issues until they actually arise. Do some tests to see how much bandwidth is actually used, and then make a decision based on that. Otherwise you might spend a lot of time fixing problems that aren’t real, instead of making your game awesome.
I think you misunderstand. The server should always do these checks, but there is no problem in letting the client do them too. It allows for less bandwidth usage (instead of going client → server → client, which takes time) it’s instant, and if the server finds the action to be invalid, it will notify the client which will then update the items accordingly.
I actually really like this method, and I think it will mitigate the need to even update the inventory when its opened, I can just assume that the server side checks will pass and visually add it to the inventory (obv not actually adding, just visuals).