Requested Module cannot be loaded inside a plugin

Hi there, so I was learning how to use plugins and I have a module inside the folder and a script, the problem is when I try to save them locally they get saved to .rbxm which is the model file.

SS-

usually the file is saved in .lua but its not in this case
Any help is appreciated.

2 Likes

Why is it a problem? It’s supposed to be that way, and should still work. Your title sounds like an output error? Are you getting any?

1 Like

Yes, its an error in the output;

image

code that requires:

local toolbar = plugin:CreateToolbar("Custom Script Tools")

local newScriptButton = toolbar:CreateButton("yep", "hmm", "rbxassetid://4458901886")

local LabeledSlider = require(script.Parent.LabeledSlider)

because of this error my code stops running, I know I can wrap it in a pcall but I want to require the module

This seems to be an error with the code within the ModuleScript itself. Could you please show us what the code looks like in the modulescript?

EDIT: I’ve looked around, and tried it for myself, and it seems like ModuleScripts do not work with plugins, so all plugin logic has to be inside scripts. You can use ModuleScripts for other things, though, but not to deal with the plugin interface, such as creating buttons, etc.

Additionally, when exporting from Roblox Studio, you’re exporting them as .rbxmx files usually. You can import these file types by dragging & dropping them into the studio window.
smallHelp

1 Like

image
uiDesign by Stelrex does stuff with modules. Not only this plugin but I have seen numerous plugin do the same.

and also the module I am using was uploaded by roblox themselve :stuck_out_tongue:

link; https://github.com/Roblox/StudioWidgets

happy cake day btw

2 Likes

You can’t use modules for plugin stuff, such as creating a button or toolbar, but anything else should work fine.

I’m sorry if I was unclear. But going back to my first question, could we see what code there in the module?

thanks for cake day btw

1 Like

Sorry, my bad I misread it.

Here is the module code:

----------------------------------------
--
-- LabeledSlider.lua
--
-- Creates a frame containing a label and a slider control.
--
----------------------------------------
GuiUtilities = require(script.Parent.GuiUtilities)
rbxGuiLibrary = require(script.Parent.RbxGui)

local kSliderWidth = 100

local kSliderThumbImage = "rbxasset://textures/TerrainTools/sliderbar_button.png"
local kPreThumbImage = "rbxasset://textures/TerrainTools/sliderbar_blue.png"
local kPostThumbImage = "rbxasset://textures/TerrainTools/sliderbar_grey.png"

local kThumbSize = 13

local kSteps = 100

LabeledSliderClass = {}
LabeledSliderClass.__index = LabeledSliderClass

function LabeledSliderClass.new(nameSuffix, labelText, sliderIntervals, defaultValue)
	local self = {}
	setmetatable(self, LabeledSliderClass)

	self._valueChangedFunction = nil

	local sliderIntervals = sliderIntervals or 100
	local defaultValue = defaultValue or 1

	local frame = GuiUtilities.MakeStandardFixedHeightFrame('Slider' .. nameSuffix)
	self._frame = frame

	local label = GuiUtilities.MakeStandardPropertyLabel(labelText)
	label.Parent = frame
	self._label = label

	self._value = defaultValue

	 --steps, width, position
	local slider, sliderValue = rbxGuiLibrary.CreateSlider(sliderIntervals, 
	    kSteps, 
		UDim2.new(0, 0, .5, -3))
	self._slider = slider
	self._sliderValue = sliderValue
	-- Some tweaks to make slider look nice.
	-- Hide the existing bar.
	slider.Bar.BackgroundTransparency = 1
	-- Replace slider thumb image.
	self._thumb = slider.Bar.Slider
	self._thumb.Image = kSliderThumbImage
	self._thumb.AnchorPoint = Vector2.new(0.5, 0.5)
	self._thumb.Size = UDim2.new(0, kThumbSize, 0, kThumbSize)
	
	-- Add images on bar.
	self._preThumbImage = Instance.new("ImageLabel")
	self._preThumbImage.Name = "PreThumb"
	self._preThumbImage.Parent = slider.Bar
	self._preThumbImage.Size = UDim2.new(1, 0, 1, 0)
	self._preThumbImage.Position = UDim2.new(0, 0, 0, 0)
	self._preThumbImage.Image = kPreThumbImage
	self._preThumbImage.BorderSizePixel = 0

	self._postThumbImage = Instance.new("ImageLabel")
	self._postThumbImage.Name = "PostThumb"
	self._postThumbImage.Parent = slider.Bar
	self._postThumbImage.Size = UDim2.new(1, 0, 1, 0)
	self._postThumbImage.Position = UDim2.new(0, 0, 0, 0)
	self._postThumbImage.Image = kPostThumbImage
	self._postThumbImage.BorderSizePixel = 0

	sliderValue.Changed:connect(function()
		self._value = sliderValue.Value

		-- Min value is 1.
		-- Max value is sliderIntervals.
		-- So scale is...
		local scale = (self._value - 1)/(sliderIntervals-1)

		self._preThumbImage.Size = UDim2.new(scale, 0, 1, 0)
		self._postThumbImage.Size = UDim2.new(1 - scale, 0, 1, 0)
		self._postThumbImage.Position = UDim2.new(scale, 0, 0, 0)
		
		self._thumb.Position = UDim2.new(scale, 0, 
			0.5, 0)

		if self._valueChangedFunction then 
			self._valueChangedFunction(self._value)
		end
	end)
	
	self:SetValue(defaultValue)
	slider.AnchorPoint = Vector2.new(0, 0.5)
	slider.Size = UDim2.new(0, kSliderWidth, 1, 0)
	slider.Position = UDim2.new(0, GuiUtilities.StandardLineElementLeftMargin, 0, GuiUtilities.kStandardPropertyHeight/2)
	slider.Parent = frame
	
	return self
end

function LabeledSliderClass:SetValueChangedFunction(vcf)
	self._valueChangedFunction = vcf
end

function LabeledSliderClass:GetFrame()
	return self._frame
end

function LabeledSliderClass:SetValue(newValue)
	if self._sliderValue.Value ~= newValue then
		self._sliderValue.Value = newValue
	end
end

function LabeledSliderClass:GetValue()
	return self._sliderValue.Value
end


return LabeledSliderClass

Main Script:

local toolbar = plugin:CreateToolbar("Custom Script Tools")

local newScriptButton = toolbar:CreateButton("yep", "hmm", "rbxassetid://4458901886")
local LabeledSlider = require(script.Parent.LabeledSlider)

-- Widget Info
local widgetInfo = DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Float,  
	true,  
	true,  
	200,    
	300,   
	150,    
	150   
)
 
newScriptButton.Click:Connect(function() -- When button clicked
	
local testWidget = plugin:CreateDockWidgetPluginGui("TestWidget", widgetInfo)
testWidget.Title = "Test Widget" 

local slider = LabeledSlider.new(
	"suffix", -- name suffix of gui object
	"labelText", -- title text of the multi choice
	100, -- how many intervals to split the slider into
	50 -- the starting value of the slider
)

-- get/set values
slider:SetValue(0)
print(slider:GetValue())

-- fire function when slider value changes
slider:SetValueChangedFunction(function(newValue)
	print(newValue)
end)

-- use :GetFrame() to set the parent of the LabeledSlider
slider:GetFrame().Parent = testWidget
end)

bump because I still dont get what I am doing wrong

Instead of parenting it to the script you could just upload it and take advantage of the require function lol

I’ve answered a similar question here.

if you want to obtain children of a plugin. (like a module script) then you have to setup your plugin correctly.

1).simply place your main script inside of a model/folder
2).throw all of your ModuleScripts and/or GUIObjects into the model/folder as well.
3).now you can grab/require children with ‘script.Parent’
4).when you upload your plugin, you’ll just upload the model/folder

Main script

local p = script.Parent
local module = require(p:WaitForChild("ModuleScript"))
local gui = p:WaitForChild("ScreenGui")

as a side note, if you don’t want your module script to be a child of the plugin, then you’ll have to upload the modulescript. (make sure its named “MainModule” and then you can just require it by its Asset_ID after uploading, I don’t know if plugins can require modules like this though I’ve never tried)

3 Likes

image
I tried this it didnt work

Oh yes thanks I forgot to try this out

its saying that your module script contained an error and couldn’t load.

could I see the full output with all errors?

EDIT: also you cannot use the ‘plugin’ keyword within module scripts. (if that’s what your doing)

Thank you so much for helping this worked, I wish I had realized this earlier and not wasted 5 hours on this

no problem, glad you got it working.

1 Like