darraghd493

Improved Basic Protect Gui

Oct 28th, 2025 (edited)
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. --[[
  2.     Improved Basic Protect Gui by darraghd493
  3.  
  4.     An improved variant of my Basic Protect Gui @ https://pastebin.com/QkvCpyKq
  5. ]]
  6.  
  7. local CoreGui = game:GetService("CoreGui")
  8.  
  9. local function randomString(len)
  10.     local charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  11.     local result = {}
  12.     for i = 1, len do
  13.         result[i] = charset:sub(math.random(1, #charset), math.random(1, #charset))
  14.     end
  15.     return table.concat(result)
  16. end
  17.  
  18. local protectgui = protect_gui or protectgui
  19. local gethui = get_hidden_gui or gethui
  20.  
  21. local protectedInstances = {}
  22. local active = false
  23.  
  24. local function init()
  25.     if active then return end
  26.     active = true
  27.  
  28.     local old
  29.     old = hookmetamethod(game, "__namecall", function(...)
  30.         local args = {...}
  31.         if not checkcaller() and args[1] == game and getnamecallmethod() == "FindFirstChild" and args[3] == true then
  32.             for _, v in ipairs(protectedInstances) do
  33.                 if v.Name == args[2] then
  34.                     return nil
  35.                 end
  36.             end
  37.         end
  38.         return old(...)
  39.     end)
  40. end
  41.  
  42. local function protect(gui)
  43.     gui.Name = randomString(32)
  44.  
  45.     if protectgui then
  46.         protectgui(gui)
  47.         gui.Parent = CoreGui
  48.         return
  49.     end
  50.  
  51.     if gethui then
  52.         gui.Parent = gethui()
  53.         return
  54.     end
  55.  
  56.     init()
  57.     table.insert(protectedInstances, gui)
  58.     for _, v in pairs(gui:GetDescendants()) do
  59.         table.insert(protectedInstances, v)
  60.     end
  61.  
  62.     gui.Parent = CoreGui
  63.     gui.DescendantAdded:Connect(function(v)
  64.         table.insert(protectedInstances, v)
  65.     end)
  66. end
  67.  
  68. return protect
  69.  
Advertisement
Add Comment
Please, Sign In to add comment