"Main is not a valid member of script" plugin issue

Hello, hope you are doing well :slight_smile:

I have been trying to learn on how to make plugins to make my life easier (based off my other post), yet I encountered another issue.

I want to create a frame that pops up whenever I click the plugin button, yet it always errors whenever I try to publish the script as a local plugin and throws the error Main is not a valid member of Plugin "user_addborder.lua"

I have tried parenting the script to the screengui that I am using, parenting the screengui to the script, yet nothing worked.

Here is hat I have so far:
image

local selection = game:GetService('Selection')
local toolbar = plugin:CreateToolbar('Add Border Around Parts')

local pluginButton = toolbar:CreateButton(
	'Add border',
	'Button to add a border around a part',
	'http://www.roblox.com/asset/?id=1557174355'
)

local info = DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Float,
	false,
	false,
	500,
	500,
	100,
	100
)

local widget = plugin:CreateDockWidgetPluginGui(
	'Add Border',
	info
)

widget.Title = 'Add a border around a part!'
script.Main.Main.Parent = widget
pluginButton.Click:Connect(function()
	widget.Enabled = not widget.Enabled
end)

local add = script.Main.Main.Add
local amount = script.Main.Main.Amount

The main problem should be around here:

local widget = plugin:CreateDockWidgetPluginGui(
	'Add Border',
	info
)

widget.Title = 'Add a border around a part!'
script.Main.Main.Parent = widget
pluginButton.Click:Connect(function()
	widget.Enabled = not widget.Enabled
end)

I would appreciate any help, thanks!

1 Like

Haven’t dealt with plugins in this way in a while, so it may take a couple of attempts for me to get the information correct.

I believe that when you use the Save as plugin option on a script object, it only stores the script (as a .lua object).

In order to save a GUI with it, you should contain the entire plugin in a folder, and use the Save as Plugin button on the folder instead. I believe that you would also then need to change the name of the script, probably to Main or something similar (again, can’t remember exact details).

1 Like

This precisely, you can structure your plugin something like this instead:
3762e8b1af06c81cc767dc962383ecdd96d88b45

Image from A comprehensive guide on making Roblox Plugins

It gives the same error.

I am only using “Save as local plugin” at the moment, and I am not sure if it should be done that way or not.

And I tried putting the script inside the startergui and saving the startergui that way, but nothing worked. It can’t seem to find the frame Main in the BorderGui screengui (I renamed the screengui btw)

Save as local plugin should be fine. For your most recent attempt, what were the exact steps you took?

1 Like
  1. I Created a folder
  2. I put the screengui and the serverscript in the folder
  3. I updated the script so it parents the frame inside the screengui to the widget variable
  4. I saved the folder as a local plugin

After all of that I still got the error: Main is not a valid member of ScreenGui "user_addborder.rbxmx.Plugin.BorderGui"

Try parenting it to game:GetService(“CoreGui”) instead

Parenting the frame to CoreGui?

That would probably work, but once again, it can’t find the frame Main inside the screengui BorderGui, so the parenting isn’t the issue, it is finding the frame.

image

1 Like

You’re saving your plugin as a .lua file, which doesn’t save Roblox instances. What you should do is, as Seargent and Siydge said, parent your script to a folder and save the folder as a plugin.

Then, you’re parenting script.Main.Main to a widget but later try to access it from the script again. So you should just make a variable for script.Main.Main and use that to access the frame.

1 Like

FYI, it is no longer script.Main.Main but script.Parent.BorderGui.Main

And do you mean to define the frame before I set its parent? Because that is what I have done, still not working.For some reason it just cannot find the frame Main inside the BorderGui. Either it can’t find the screengui or it can’t find the frame.

1 Like

What’s the error that the output gives you?

I’ll also try to recreate the problem once I get on my computer.

Main is not a valid member of ScreenGui "user_addborder.rbxmx.Plugin.BorderGui" is the error it gives me.

If you need the entire script, I will send it here:

local selection = game:GetService('Selection')
local toolbar = plugin:CreateToolbar('Add Border Around Parts')

local pluginButton = toolbar:CreateButton(
	'Add border',
	'Button to add a border around a part',
	'http://www.roblox.com/asset/?id=1557174355'
)

local info = DockWidgetPluginGuiInfo.new(
	Enum.InitialDockState.Float,
	false,
	false,
	500,
	500,
	100,
	100
)

local widget = plugin:CreateDockWidgetPluginGui(
	'Add Border',
	info
)

local mainframe = script.Parent.BorderGui.Main

widget.Title = 'Add a border around a part!'
mainframe.Parent = game:GetService('CoreGui')
pluginButton.Click:Connect(function()
	widget.Enabled = not widget.Enabled
end)

local add = mainframe.Add
local amount = mainframe.Amount

local function addBorder(part:Part,x:boolean,y:boolean,borderWidth:number?): nil --assumes part is not rotated at all
	local borderWidth:number = borderWidth or 1

	if x then
		local offset:number = (part.Size.Z/2)+(borderWidth/2)

		for i=1,2 do --make both parts
			if type(part) == 'table' then
				for _, p in y do
					if p:IsA('Part') then
						local borderPart:Part = Instance.new("Part")
						borderPart.Anchored = true
						borderPart.Size = Vector3.new(p.Size.X+(y and borderWidth*2 or 0),p.Size.Y,borderWidth)
						borderPart.CFrame = p.CFrame+Vector3.new(0,0,offset*(-1)^i)

						borderPart.Parent = workspace
					end
				end
			else
				local borderPart:Part = Instance.new("Part")
				borderPart.Anchored = true
				borderPart.Size = Vector3.new(part.Size.X+(y and borderWidth*2 or 0),part.Size.Y,borderWidth)
				borderPart.CFrame = part.CFrame+Vector3.new(0,0,offset*(-1)^i)
				borderPart.Parent = workspace
			end
		end
	end

	if y then
		local offset:number = (part.Size.X/2)+(borderWidth/2)

		for i=1,2 do --make both parts
			if type(part) == 'table' then
				for _, p in y do
					if p:IsA('Part') then
						local borderPart:Part = Instance.new("Part")
						borderPart.Anchored = true
						borderPart.Size = Vector3.new(borderWidth,part.Size.Y,part.Size.Z)
						borderPart.CFrame = part.CFrame+Vector3.new(offset*(-1)^i,0,0)

						borderPart.Parent = workspace
					end
				end
			else
				local borderPart:Part = Instance.new("Part")
				borderPart.Anchored = true
				borderPart.Size = Vector3.new(borderWidth,part.Size.Y,part.Size.Z)
				borderPart.CFrame = part.CFrame+Vector3.new(offset*(-1)^i,0,0)

				borderPart.Parent = workspace
			end
		end
	end

	return nil
end

selection.SelectionChanged:Connect(function()
	add.MouseButton1Click:Connect(function()
		local am = tonumber(amount.Text) or 1
		addBorder(selection:Get(), true, true, am)
	end)
end)

Don’t worry about fixing any bugs in the code except the problem I am having right now, I will take care of that.

image

1 Like

I’m unable to replicate the error, the plugin runs fine for me.

Are you making sure to save the folder itself, as a local plugin? If you are, then just to be sure there’s no random characters in the names of stuff, change just edit the names, clear them and rewrite “Main”, etc, who knows if there’s an invisible character or space in there.

Here’s my copy of it if that helps:
Plugin.rbxm (11.2 KB)

I just tried it out, and I’m getting no errors. Maybe you just forgot to save your plugin again?

Also for some reasons you’re parenting the UI to CoreGui? It should be parented to the widget.

Honestly, I have no idea what the problem is…

Thanks for the file, appreciate it!

Yup, I fixed that, no worries!

Thanks for trying :slight_smile:

1 Like

I think I know what the problem is:

This happened a while back, I was doing something with the frames at an old project that I am still working on, yet for some reason roblox couldn’t “save” the frame, so it rendered it as nil. I think the same thing just happened, which could be the studio’s fault.

Once again, appreciate the help :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.