Advertisement
StefanBashkir

Distance-based BillboardGUI Hider Thing

May 2nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.25 KB | None | 0 0
  1. local bGUIs = {}
  2. local player = game.Players.LocalPlayer
  3. local playerGUI = player:WaitForChild("PlayerGui")
  4.  
  5. local function getAllBillboardGuis(parent)
  6.     local iterations = 0 -- every 200, wait() (reduces lag)
  7.     local guis = {}
  8.     local function get(p)
  9.         for i,v in pairs(p:GetChildren()) do
  10.             iterations = iterations + 1
  11.             if (iterations % 200 == 0) then
  12.                 wait()
  13.             end
  14.             if (#v:GetChildren() > 0) and (not v:IsA("BillboardGui")) then
  15.                 get(v)
  16.             elseif (v:IsA("BillboardGui")) then
  17.                 table.insert(guis, v)
  18.             end
  19.         end
  20.     end
  21.     get(parent)
  22.     return guis
  23. end
  24.  
  25. workspace.DescendantAdded:connect(function(d)
  26.     if (d:IsA("BillboardGui")) then
  27.         repeat
  28.             wait()
  29.         until d.Parent
  30.         wait()
  31.         table.insert(bGUIs, d)
  32.     end
  33. end)
  34.  
  35. playerGUI.DescendantAdded:connect(function(d)
  36.     if (d:IsA("BillboardGui")) then
  37.         repeat
  38.             wait()
  39.         until d.Parent
  40.         wait()
  41.         table.insert(bGUIs, d)
  42.     end
  43. end)
  44.  
  45. bGUIs = getAllBillboardGuis(workspace)
  46.  
  47. while wait(0.25) do
  48.     for i,v in pairs(bGUIs) do
  49.         local part = v.Adornee or v.Parent
  50.         if (part) then
  51.             if (player:DistanceFromCharacter(part.Position) > 50) then
  52.                 v.Enabled = false
  53.             else
  54.                 v.Enabled = true
  55.             end
  56.         else
  57.             table.remove(bGUIs, i) -- cleanup dead references
  58.         end
  59.     end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement