DrawingJhon

NS and NLS modules

Aug 16th, 2020 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. -- ========== ModuleScript ========== --
  2.  
  3. local module = {}
  4.  
  5. function module.PS(code)
  6.     local Loadstring = require(script.Loadstring)
  7.     Loadstring(code)()
  8. end
  9.  
  10. function module.LoadModule(parent)
  11.     local Loadstring = script.Loadstring
  12.     local l = Loadstring:Clone()
  13.     l.Parent = parent
  14.     return l
  15. end
  16.  
  17. function module.NS(code, parent)
  18.     local Loadstring = require(script.Loadstring)
  19.     local ns = script:findFirstChild("NS")
  20.     local newScript = ns:Clone()
  21.     newScript.Parent = parent or game:GetService("ServerScriptService")
  22.     local remote = newScript:WaitForChild("RemoteSource") --BindableFunction
  23.     remote.OnInvoke = function(destroy)
  24.         if destroy then
  25.             remote:Destroy()
  26.         else
  27.             return Loadstring, code
  28.         end
  29.     end
  30.     return newScript
  31. end
  32.  
  33. function module.NLS(code, parent)
  34.     local nls = script:findFirstChild("NLS")
  35.     local newLocal = nls:Clone()
  36.     newLocal.Parent = parent
  37.     local remote = newLocal:WaitForChild("RemoteSource") --RemoteFunction
  38.     remote.OnServerInvoke = function(plr, destroy)
  39.         return code
  40.     end
  41.     return newLocal
  42. end
  43.  
  44. return module
  45.  
  46. -- ========== Script ========== --
  47.  
  48. local remote = script:WaitForChild("RemoteSource")
  49. local Loadstring, source = remote:Invoke()
  50. remote:Invoke(true)
  51. Loadstring(source, getfenv())()
  52.  
  53. -- ========== LocalScript ========== --
  54.  
  55. local remote = script:WaitForChild("RemoteSource")
  56. local Loadstring = require(script:WaitForChild("Loadstring"))
  57. local source = remote:InvokeServer()
  58. Loadstring(source, getfenv())()
Add Comment
Please, Sign In to add comment