I am obviously doing checks on the server. My question here is in terms of performance/suitability for checks on the client before sending a request to the server.
When I want to check if the client data meets a particular condition, should I be invoking the server to request the client’s data and using it to perform the client check or should I instead keep a cache of the client data, which in turn is updated whenever the client data on the server is changed by firing an event back to the client to update the cache?
Giving a pseudo-code example here:
local clientData = requestData:InvokeServer()
if clientData.money >= 50 then
--code
end
or from a cache:
local cache = {
money = 50
}
local function hasEnoughMoney()
if cache.money >= 50 then
--code
end
end
dataUpdated.OnClientEvent:Connect(function(newData)
cache = newData
end)
My idea is for the latter as if the data hasn’t changed I don’t see a need to bother the server with such a request as the serverside will handle any final checks regardless and the cache will be updated whenever the data changes on the server anyway, although I’d like to hear other thoughts.