ModReload - Reload Your Modules With Ease


ModReload is a simple plugin so you can reload your modules without using any of the following methods.

Methods
  1. Pressing Play (or Run) and then immediately ending the playtest to reload (goodluck if your on a low-end pc :nauseated_face:)

  2. 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 :skull:)

  3. 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 :coefficients:)

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)

How is this any different to the “Reload Script” button in Studio? I’m curious

1 Like

I’m fairly certain they’re about to realize that that exists
420acc3a36551f18f01c9f6774a1e63c

1 Like

Wait does that actually work :skull: i’ll go see if it does, but i think i might’ve wasted my time on this script :frowning: welp, it doesn’t matter, it was a fun little project to work on, plus it’s faster for me to reload like this.

Works just fine. And on the 1 in 1000 times that it doesn’t, I just cut and paste the modulescript. fixes it too.

Well thats neat, i’ll see if there’s any other features i could add to this that’ll make it more useful, thanks for letting me know.

Perhaps you can use the script to do UI hotfixing; there is no native support for that yet.

Hmm, that sounds interesting, but i’ve never heard of it before, could you elaborate?

Automatically refreshing a UI based on script changes, so you do not need to playtest to see them.

so like being able to visualize UI created from a script without playtesting? or update the UI based on a script that modifies it? sorry if I’m misunderstanding.

oh btw, i can’t seem to find the reload script button using the new studio UI, so i guess there’s another rare reason for this plugin to exist :coefficients: (btw i updated the script to actually reload modules in the correct order now :D)