Billboard Gui visible detection

I was wondering if any of you know a method of detecting when a BillboardGui is visible or not.
By this I mean the BillboardGui is enabled, has MaxDistance set at 10 studs and a script being able to detect if the BillboardGui is visible on the screen or not.

Billboard is enabled, 10 studs away from it
image

Billboard is still enabled but now visible as I’m within 10 studs
image

Is there any way to detect this?

1 Like

not directly afaik. but you could check the distance between the player and the object.

local distance = (player.PrimaryPart.Position - guiHolder.Position).magnitude
if distance < 10 then
 -- is visible
else
-- not visible 
end
2 Likes

Would be cool if we could get an event on the BillboardGui such as

billboard.VisibleToPlayer:Connect(function(player)
    -- blah
end)
7 Likes

i think that provided that there is an otherwise very easy way to arrive at the same outcome, while it may be more convenient, another property/event would just bloat the api unnecessarily.

1 Like

If you want to see if the billboardGui, or rather, the part it is adorned to, is visible on screen, use this method:

local _,isPartOnScreen = workspace.CurrentCamera:WorldToScreenPoint(part.Position)

isPartOnScreen is a bool, and here’s the documentation for the method.

8 Likes

I second this. Along with checking the distance to the player.

I’d also add that the Camera:WorldToScreenPoint() does return the distance to the GUI as well. Like so:

local guiPosition
local camera
local screenPos, visible = camera:WorldToScreenPoint(guiPosition)
local distanceToGuiPosition = screenPos.Z

Using this method to find the distance would be more accurate than using the player position. I’m not sure if the Gui’s use the distance from the player’s clipping plane, or camera origin though. To be precise, you’d need to do some testing.

2 Likes

i know this post is 5 years old, damn but i just found the solution.

well simply there is no solution so you need to think out of the box, what i did here is made the maxdistance manual, so my script checks if the player is close to make it enabled, heres the script

wait() -- just to wait till the character loads.

local player = game.Players.LocalPlayer.Character -- simply gets the player character and puts it in a variable

while task.wait(0.1) do -- checks constantily for the player position
	
local distance = (player.PrimaryPart.Position - script.Parent.Adornee.Position).magnitude -- script.parent is basically the billboard gui, and this is the magnitude , or the diffrence between the player character and the billboard part's position

	if distance < 10 then -- i made it 10 you can customize it as you want, this is basically just the maxdistance
		 
		script.Parent.Enabled = true -- makes billboard visible because player in set distance
		
	else

		script.Parent.Enabled = false -- makes billboard invisible because player too far
		
	end
end

so with this script we manually enable the billboard gui, and then make it visible,

you can just do the script you want to do when the billboard gui becomes visible, or you can make an another script that has GetPropertyChangedSignal(“Enabled”) and use that function.

note: make the billboard gui max distance infinity (inf)

also note: that all these scripts are local, unless for some reason you want to make the billboard gui visible to all player when any player gets close to it