I've been thinking about this for a while, but I can't seem to get exactly what I am looking for.
Basically, I have a single BillboardGui
located in every player, and when they get close to a specific object, that GUI will adorn to that part, making it visible on the part. Note that this will only happen on specific parts, let's say we identify these parts by the names PartA and PartB. PartA and PartB have different GUI content, but that's not the focus here. So if the player gets close to either PartA or PartB, they will see the gui at the position of that part. There can only be one GUI active at a time, so I don't want the player to see the GUI on 5 different parts. That's why I'm using one GUI and setting its Adornee
property.
I'd much rather have this than have a BillboardGui in every PartA and PartB, and set their Visible
options to false/true when necessary.
One of my ideas was simply creating an additional transparent part that surrounds PartA and PartB, so when the player touches it, they will see the GUI over that object. With this, there is the issue of PartAs and PartBs potentially overlapping and causing chaos with the GUI. Also, if the player touches one of the parts, and gets very close to another PartA/PartB then the GUI will still be on the initial part, even though the player is much closer to the latter part. The GUI should adorn to whichever part is closest.
I tried to use the camera with things like its lookvector
property on the CFrame, and WorldToScreenPoint
function but I am generally horrible with camera work and that did not go far. I feel like camera work is not necessary for this problem.
Essentially I just need to know how far every one of the PartAs and PartBs are from my character, but I don't want to create a ton of unnecessary network communication (getting distances from parts that are very very far away), and I'm not sure how to constantly get information about the parts that are near my character. If there was some sort of function like
player:GetNearbyParts(radius)
then that would be perfect.
I know this is a long question but I just wanted to give as much details as possible so you guys could help me out! Thanks :)