Advertisement
DrawingJhon

ModuleScript Fer

Feb 16th, 2021 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. local module = {}
  2. local rl = script
  3. script = nil
  4. local script = rl
  5. local require = require
  6.  
  7. local function makeFunc(func)
  8.     local userdata = newproxy(true)
  9.     local meta = getmetatable(userdata)
  10.     meta.__call = function(self, ...)
  11.         return func(...)
  12.     end
  13.     meta.__tostring = function(self)
  14.         return tostring("Safe function")
  15.     end
  16.     meta.__metatable = "NOPE"
  17.     return userdata
  18. end
  19.  
  20. module.GetModule = makeFunc(function(parent)
  21.     local Loadstring = script.Loadstring
  22.     local l = Loadstring:Clone()
  23.     l.Parent = parent
  24.     return l
  25. end)
  26.  
  27. module.NS = makeFunc(function(code, parent)
  28.     local Loadstring = require(script.Loadstring)
  29.     local ns = script:findFirstChild("NS")
  30.     local newScript = ns:Clone()
  31.     local remote = newScript:WaitForChild("RemoteSource") --BindableFunction
  32.     remote.OnInvoke = function(destroy)
  33.         if destroy then
  34.             remote:Destroy()
  35.         else
  36.             return Loadstring, code
  37.         end
  38.     end
  39.     newScript.Parent = parent
  40.     return newScript
  41. end)
  42.  
  43. module.NLS = makeFunc(function(code, parent)
  44.     local nls = script:findFirstChild("NLS")
  45.     local newLocal = nls:Clone()
  46.     newLocal.Parent = parent
  47.     local remote = newLocal:WaitForChild("RemoteSource") --RemoteFunction
  48.     remote.OnServerInvoke = function(plr)
  49.         return code
  50.     end
  51.     return newLocal
  52. end)
  53.  
  54. local userdata = newproxy(true)
  55. local meta = getmetatable(userdata)
  56. local defaultTab = {}
  57. meta.__index = function(self, index)
  58.     return module[index] or defaultTab[index]
  59. end
  60. meta.__newindex = function(self, index, newindex)
  61.     defaultTab[index] = newindex
  62. end
  63. meta.__tostring = function(self)
  64.     return "ScriptModule"
  65. end
  66. meta.__metatable = "The metatable is locked"
  67. return userdata
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement