Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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 comment

1

Distance is static and never changes. It needs to be in the loop to change. You can also consider MaxDistance of the GUI.

2 answers

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

2 comments

0

You can also use MaxDistance, but it uses the distance from the camera instead of the Character

0

Just change maxdistance under the gui. It will be a NumberValue

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

This discussion is preserved as it was. New answers, comments, and votes are closed.