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
Billboard is still enabled but now visible as I’m within 10 studs
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.
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.
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