Use string.length or put # infront of the variable.
If you wanna measure a table:
json encode it and then put # infront of it or again string.length.
local TableVar = {"Item1", "Item2"},
local HTTPService = game:GetService("HttpService")
local TableInJson = HTTPService:JSONEncode(TableVar)
print(#TableInJson)
Keep in mind however, the data is in bytes, to get it in kilobytes, divide by 1024!
Yes there are ways to compress tables, again by putting the table into its JSON format and then using a LZW compression system. (same applies to normal text)
how does this work when the value in a table is an Instance? I’m sending a table containing many instances to the client, and trying to measure the table size using JSONEncode is inaccurate because the instances are changed to null in the process, while remotes successfully transfer them.
We would have to assume roblox is sending the instances as unique identifiers (4 or 8 bytes) instead of as a string. Remotes are also likely sending numbers as floats (4 bytes) instead of a string. Strings are usually much more data to send, they will be one byte per character and another 1 or 4 bytes to store the end of the string.
If you are trying to reduce your game’s data throughput it’s best to reduce remote calls first then reduce strings inside those remote calls.
I’m gonna have a table on the server that’s storing a TON of data, depending on what kind of game is using that table. In a building game, for example, data about potentially thousands of parts could be stored and so if the table gets too long, I won’t be able to send all of that data to the clients in one remote call. I’m trying to figure out at what points I would be splitting the table into multiple remote calls, that’s why I need the table length in bytes.
It might look something like that, but that post is trying to get the memory address. Since the RAM in your computer isn’t the same as the Server’s RAM this address can be very different and they will need to send a unique ID both the clients and server can agree on; it may be only visible to Roblox developers
Depends on what your server-side data is, Roblox sends thousands of part updates to clients every second! Try leveraging roblox systems before using scripts in such cases. Roblox can handle updating physics much better than Lua ever could. Adding and Removing parts should be handled by Roblox, if you need to keep track of parts server-side then keep that tracking only in your server-side script.