You can write your topic however you want, but you need to answer these questions:
I want to check how many things are inside of a shared table/variable that is a table. Keep it simple and clear!
I’ve tried using # to check the amount of things inside the table, but it didn’t work since it’s a dictionary, I also thought of just making a variable and looping through the table and adding +1 to the variable for every loop, but for what I’am doing this will cause a lot of loops happening at once, and it’s also on the server, meaning it’ll be worse
local dictionary = {
["Value1"] = 5,
["Value2"] = 10,
}
print(#dictionary) -- prints 0
It’s not horrible for performance, even on task.wait() this is has linear time complexity.
Even with a large dictionary it around ~0.000008 seconds to do this operation. It’s completely fine even in a large loop. It’s optimized in the Lua JIT compiler.
Actually you could make it so anytime you add something to the dictionary you add 1 to a value and anytime somethings removed remove 1. Then just use this number