I would like to make a BillboardGui that shows when the player gets to the nearest object (Adornee) from a bunch of them.
The issue is that I am not sure which way is most efficient to achieve this.
My most comfortable approach would be to loop through the objects in RenderStepped, find the closest one, and set its Adornee. But wouldn’t that heavily affect the performance? (due to calculations and looping every frame)
Another way would be to make a Billboard GUI to each of the objects, but that would not accept user input, nor would be optimal.
Here’s some pseudo-code to give you an idea of what my first approach would look like:
local RunService = get RunService local groupOfParts = Path to parts RunService.RenderStepped -> (function() local lastPart = nil for part in groupOfParts do part_distance = (calculated part distance from player) lastPart_distance = (calculated lastPart distance from player) if(part_distance < lastPart_distance) then lastPart = part break end lastPart = part end billboard.Adornee = lastPart end)
What would be the optimal and correct way to do such a thing? Or is my first approach not performance-killing and fine to use?
Thanks in advance.