Advertisement
dennis96411

[ROBLOX Plugin] Studio Command Bar ModuleScript Auto Loader

Dec 13th, 2015
1,507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. --[[
  2.     -----Studio Command Bar ModuleScript Auto Loader by PickleSammiches-----
  3.     The purpose of this plugin is to auto-require a ModuleScript and set a reference to it for the studio command bar environment.
  4.    
  5.     Change ScriptName to the name of your ModuleScript, VariableName to the name of the variable you want to access the ModuleScript from in the command bar, and AutoReload to whether you want the variable to auto-update on source change. Add any additional scripts you would like to open up a tab for automatically to the AuxiliaryScripts table.
  6.    
  7.     On initial load, a statement will be printed by the TestService in orange. Copy and paste the last line of the statement and execute it in the command bar. This will make a reference in your studio command bar environment to your ModuleScript. If AutoReload is set to true, subsequential updates to the ModuleScript source will cause the variable to update automatically without user intervention (you MUST switch out of the source code tab/window after changing your ModuleScript's source for ROBLOX to acknowledge a change to the source).
  8. ]]
  9. ScriptName, VariableName, AutoReload = "RBXunderscore", "_", true
  10. Script, Plugin, TestService, LoadCommand = game:FindFirstChild(ScriptName, true), PluginManager():CreatePlugin(), game:GetService("TestService"), VariableName .. " = _G[\"" .. VariableName .. "\"]"
  11. AuxiliaryScripts = {
  12.     game:GetService("ServerScriptService").ServerTest
  13. }
  14.  
  15. LoadScript = function(Script, ReloadMode)
  16.     _G[VariableName] = require(Script)
  17.     if AutoReload then Script.Changed:connect(function(Property) if Property == "Source" then ReloadScript(Script) end end) end
  18.     Plugin:OpenScript(Script)
  19.     TestService:Warn(false, ReloadMode and (AutoReload and ScriptName .. " has been reloaded." or "Reload " .. ScriptName .. " (copy and execute):\n" .. LoadCommand) or ("Load " .. ScriptName .. " (copy and execute):\n" .. (AutoReload and "repeat " .. LoadCommand .. " until not wait(1)" or LoadCommand)))
  20. end
  21.  
  22. ReloadScript = function(Script)
  23.     local Source, Parent = Script.Source, Script.Parent
  24.     wait() --Prevents studio from crashing from Ctrl-Tabbing out of the ModuleScript source, because reasons
  25.     Script:Destroy() --We have to create a new script for "require" to see the new source, because more reasons
  26.     Script = ScriptCopy:Clone()
  27.     Script.Source = Source; Script.Parent = Parent; Script.Name = ScriptName
  28.     LoadScript(Script, true)
  29. end
  30.  
  31. game.DescendantAdded:connect(function(Instance)
  32.     if not DescendantAddedDebounce and pcall(function() return Instance.Name end) then
  33.         DescendantAddedDebounce = true
  34.         if Instance == Script then
  35.             ReloadScript(Script)
  36.         elseif Instance.Name == ScriptName then
  37.             LoadScript(Script)
  38.         end
  39.         wait(); DescendantAddedDebounce = false
  40.     end
  41. end)
  42.  
  43. if Script then
  44.     wait(0.5) --Let game render tab open first
  45.     ScriptCopy = Script:Clone(); ScriptCopy.Name = "" --Change name to something different from the original to avoid triggering events
  46.     table.foreach(AuxiliaryScripts, function(_, Script) Plugin:OpenScript(Script) end)
  47.     LoadScript(Script)
  48. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement