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 3 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.

local distance = (game.Players.LocalPlayer.Character.HumanoidRootPart.Position - script.Parent.Parent.Parent.Position).magnitude
while true do wait()
    if distance < 10 then
        print("visible")
    else
        print("not visible")
    end
end
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 — 3y

2 answers

Log in to vote
0
Answered by
bdam3000 125
3 years ago
Edited 3 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

local hitbox = *part here*
local gui = *billboardgui here*
local debounce = true

hitbox.Touched:Connect(function(hit)
    if hit.Name == "HumanoidRootPart" and debounce then
        gui.Enabled = true
        debounce = false
end
end)

hitbox.TouchEnded:Connect(function(x)
    if x.Name == "HumanoidRootPart" and not debounce then
        gui.Enabled = false
        debounce = true
    end
end)

LocalScript btw

0
You can also use MaxDistance, but it uses the distance from the camera instead of the Character bdam3000 125 — 3y
0
Just change maxdistance under the gui. It will be a NumberValue 2Loos 168 — 3y
Ad
Log in to vote
0
Answered by 3 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