Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a BillboardGUI dissapear at a certain range?

Asked by 4 years ago

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.

1local distance = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - script.Parent.Parent.Parent.Position).magnitude
2while true do wait()
3    if distance < 10 then
4        print("visible")
5    else
6        print("not visible")
7    end
8end
1
Distance is static and never changes. It needs to be in the loop to change. You can also consider MaxDistance of the GUI. DeceptiveCaster 3761 — 4y

2 answers

Log in to vote
0
Answered by
bdam3000 125
4 years ago
Edited 4 years ago

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

01local hitbox = *part here*
02local gui = *billboardgui here*
03local debounce = true
04 
05hitbox.Touched:Connect(function(hit)
06    if hit.Name == "HumanoidRootPart" and debounce then
07        gui.Enabled = true
08        debounce = false
09end
10end)
11 
12hitbox.TouchEnded:Connect(function(x)
13    if x.Name == "HumanoidRootPart" and not debounce then
14        gui.Enabled = false
15        debounce = true
16    end
17end)

LocalScript btw

0
You can also use MaxDistance, but it uses the distance from the camera instead of the Character bdam3000 125 — 4y
0
Just change maxdistance under the gui. It will be a NumberValue 2Loos 168 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

There is a property of the BillboardGUI called "MaxDistance" and it is exactly what you're looking for and measured in studs.

Answer this question