Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Basic Protect Gui by darraghd493
- This is a basic module which prevents a gui from being indexed, offering basic protection.
- ]]
- local library = {
- protected = {},
- connections = {} -- { gui = connection }
- }
- local oldNc;
- oldNc = hookmetamethod(game,"__namecall",function(...)
- local args = {...}
- if not checkcaller() and args[1] == game and getnamecallmethod() == "FindFirstChild" and args[3] == true then
- for i, v in pairs(library.protected) do
- if v.Name == args[2] then
- return nil
- end
- end
- end
- return oldNc(...)
- end)
- function library.protect(gui: ScreenGui)
- table.insert(library.protected, gui)
- for i, v in pairs(gui:GetDescendants()) do
- table.insert(library.protected, v)
- end
- library.connections[gui] = gui.DescendantAdded:Connect(function(v)
- table.insert(library.protected, v)
- -- Ensure the connection is not active when the gui is not protected
- if not table.find(library.protected, gui) then
- library.connections[gui]:Disconnect()
- end
- end)
- end
- function library.unprotect(gui: ScreenGui)
- table.remove(library.protected, table.find(library.protected, gui))
- for i, v in pairs(gui:GetDescendants()) do
- table.remove(library.protected, table.find(library.protected, v))
- end
- if library.connections[gui] then
- library.connections[gui]:Disconnect()
- end
- end
- return library
Advertisement
Add Comment
Please, Sign In to add comment