Hello! In my game I want to use an interaction system where whenever player points their mouse at something that is tagged “Interactable”, an interaction GUI appears. I want to use table.find() to check if is the part interactable. However, I’m worried that if I use table.find() very frequently at a large table then it would cause lag. Are my worries right? And if they are, what function should I use instead?
I wouldn’t think it is since it’s not doing a really heavy task, Roblox’s engine is probably more than capable of iterating through text and tables at a very high rate. But if it were to cause lag, I wouldn’t use a table in order to store which parts are “Interactable.” I’d just insert a BoolValue (or anything, really) into all parts that are intractable, and if a player hovers their mouse over a part which has this “Interactable” child, then the GUI appears.
I assume that
table.find has O(n) performance. In other words, the worst-case scenario will cause it to scan through the whole table once. That’s not necessarily bad, unless you have a ton of parts or are running the operation very frequently. The best way to find out is to simply test it. Try to make it lag. Keep making the table bigger until you have problems.
Just throwing in some more info. I think @Chatowillwin is correct to do something like a BoolValue. You could also use the CollectionService too and check if the part is tagged properly.