Hi. I want a BillboardGUI to be visible when you're close to it, but disappear when you get too far away.
I tried this script, but it doesnt seem to work.
1 | local distance = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - script.Parent.Parent.Parent.Position).magnitude |
2 | while true do wait() |
3 | if distance < 10 then |
4 | print ( "visible" ) |
5 | else |
6 | print ( "not visible" ) |
7 | end |
8 | end |
Might not be the most efficient way to do this, but I thought I'd share this anyway
You can make a hitbox for the part, so when the player touches the hitbox, the Gui will be enabled
01 | local hitbox = *part here* |
02 | local gui = *billboardgui here* |
03 | local debounce = true |
04 |
05 | hitbox.Touched:Connect( function (hit) |
06 | if hit.Name = = "HumanoidRootPart" and debounce then |
07 | gui.Enabled = true |
08 | debounce = false |
09 | end |
10 | end ) |
11 |
12 | hitbox.TouchEnded:Connect( function (x) |
13 | if x.Name = = "HumanoidRootPart" and not debounce then |
14 | gui.Enabled = false |
15 | debounce = true |
16 | end |
17 | end ) |
LocalScript btw
There is a property of the BillboardGUI called "MaxDistance" and it is exactly what you're looking for and measured in studs.