plytalent

LibraryUtils

Apr 5th, 2022 (edited)
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. local print = rconsoleinfo or print
  2. local module
  3.  
  4. function findvalue_in_table(value,tb)
  5.     for _,v in pairs(tb) do
  6.         if value == v then
  7.             return true
  8.         end
  9.     end
  10.     return false
  11. end
  12.  
  13. function gethttp(url)
  14.     local sus, errorstatement = pcall(function()
  15.         return game:HttpGet(url)
  16.     end)
  17.     if sus then
  18.         return errorstatement
  19.     else
  20.         print("[Library Loader][Get Http]FAILED".. errorstatement)
  21.         return "ERROR"
  22.     end
  23. end
  24.  
  25. module = {
  26.     LocalLoad = function(path_to_file)
  27.         local path_to_file = path_to_file or ""
  28.         local LibraryContent = readfile(path_to_file) or ""
  29.         local n_er, Library = pcall(function()
  30.             return loadstring(LibraryContent)()
  31.         end)
  32.         if n_er then
  33.             return Library
  34.         end
  35.     end,
  36.     ExternalLoad = function(url)
  37.         local url = url or ""
  38.         local LibraryContent = gethttp(url)
  39.         if LibraryContent == "ERROR" then
  40.             print("[Library Loader][URL Loader]FAILED TO LOAD EXTERNAL LIB"..LibraryContent)
  41.             return
  42.         end
  43.         local n_er, Library = pcall(function()
  44.             return loadstring(LibraryContent)()
  45.         end)
  46.         if n_er then
  47.             return Library
  48.         end
  49.     end,
  50.     Load = function(modulename)
  51.         print("Loading"..modulename)
  52.         if not isfolder("module") then
  53.             makefolder("module")
  54.         end
  55.         local modules = listfiles("module")
  56.         if findvalue_in_table(modulename,modules) then
  57.             return module.LocalLoad("module/"..modulename..".lua")
  58.         else
  59.            
  60.             local ScriptFromRepo = gethttp("https://raw.githubusercontent.com/plytalent/Roblox-Library-Repo/main/"..modulename:gsub("%s+","%%20")..".lua")
  61.             if ScriptFromRepo ~= "404: Not Found" then
  62.                 return module.ExternalLoad(ScriptFromRepo)
  63.             else
  64.                 rconsoleinfo("NOT FOUND MODULE")
  65.             end
  66.         end
  67.     end
  68. }
  69. return module
Add Comment
Please, Sign In to add comment