ModReload is a simple plugin so you can reload your modules without using any of the following methods.
Methods
-
Pressing Play (or Run) and then immediately ending the playtest to reload (goodluck if your on a low-end pc )
-
Copying the module’s code, making a new module, and then placing the code back in to reload (why would you do this that’s cursed )
-
Right-Clicking, downloading the module to your pc, then importing it back in to reload (i used to use this method but its too tedious bruh )
Anyways, here’s the module, i’d recommend making it a keyboard shortcut for ease of use.
How To Use
Just select a module and click the shortcut and it’ll reload it very quickly,
if you have multiple module tabs open, it’ll reload those modules too and in the order they were before, and also, don’t worry about module code loss, it reloads fast enough that it shouldn’t be a issue, but you can make a backup if anything does go wrong though.
BTW! i have something BIG that I’m working on currently, which I’ll open-source once I’m finished! so stay tuned for that…
Source Code
--!nocheck
--//VARIABLES
local clicked: boolean = false
local attributes: {[string]: string | number} = script.Parent:GetAttributes()
local plugin: Plugin = plugin
local toolbar: PluginToolbar = plugin:CreateToolbar(attributes["ToolbarName"])
local icon: string
if attributes["Icon"] then
if attributes["Icon"]:find("rbxassetid://") then
icon = attributes["Icon"]
else
icon = "rbxassetid://"..attributes["Icon"]
end
end
local button: PluginToolbarButton = toolbar:CreateButton(
attributes["Name"],
attributes["Tooltip"],
icon
)
button.ClickableWhenViewportHidden = true
local scriptEditorService = game:GetService("ScriptEditorService")
local moduleDictionary = {}
local iteration = 1
button.Click:Connect(function(): ()
clicked = not clicked
if clicked == true then
local function reload(module: ModuleScript): ()
if module and module:IsA("ModuleScript") then
-- module children loop
for _, i: any in pairs(module:GetChildren()) do
if i:IsA("ModuleScript") then
local newDescendantSource = Instance.fromExisting(i)
newDescendantSource.Parent = i.Parent
if scriptEditorService:FindScriptDocument(i) then
moduleDictionary[iteration] = newDescendantSource
iteration += 1
end
i:Destroy()
end
end
-- module reloading
local newSource = Instance.fromExisting(module)
newSource.Parent = module.Parent
for _, i: any in pairs(module:GetChildren()) do
i.Parent = newSource
end
if scriptEditorService:FindScriptDocument(module) then
moduleDictionary[0] = newSource
end
module:Destroy()
end
for i = 0, iteration do
if moduleDictionary[i] then
scriptEditorService:OpenScriptDocumentAsync(moduleDictionary[i])
end
end
end
-- scripting tabs loop
for _, i: ScriptDocument in pairs(scriptEditorService:GetScriptDocuments()) do
pcall(function()
if i and i:GetScript() then
if i:GetScript().Parent:IsA("ModuleScript") then
reload(i:GetScript().Parent)
elseif i:GetScript():IsA("ModuleScript") then
reload(i:GetScript())
end
end
end)
end
-- selection loop
for _, i: any in pairs(game:GetService("Selection"):Get()) do
if i.Parent:IsA("ModuleScript") then
reload(i.Parent)
elseif i:IsA("ModuleScript") then
reload(i)
end
end
clicked = false
end
end)