How to check resources on a table instead of having 6 different if statements?

I need a way to instead of doing a check specifically on game.Workspace.SilverOre.Position, because I want to be able to check their distance for every resource, and I don’t want to have 6 different if statements checking for each resource. I imagine I would have to use a table, but I’m unsure. Can someone help, what could I do?

1 Like

Fixed it myself. The solution I did was I added a for loop to loop through a folder of the collectable Instances, and checked their Main part’s position.

2 Likes

For further optimization if you need to otherwise your method should do fine, consider:

  1. Doing this for loop computation locally then fire the server with a server side distance check.

  2. Using octrees with a radius search to narrow down the number of resources. (Not 100% sure, just know that octrees can get the nearest neighbors fast).

2 Likes