Module I'm making errors at returning? Why?

๐“๐ก๐ข๐ฌ ๐ก๐š๐ฌ ๐›๐ž๐ž๐ง ๐ฌ๐จ๐ฅ๐ฏ๐ž๐!

Here is the error for context:

Error
Other Error

In case your wondering:

Name of Module

Iโ€™ve been making a module called โ€œPluginServiceโ€ for a couple days now, but for some reason itโ€™s erroring at returning. Iโ€™ve researched it and canโ€™t seem to find a solution. :wut:

Please provide me with any information you may have on this matter. :happy3:
Appreciate your help!!! :happy3:

Script: (very long ngl :doh:)

local PluginService = {}

--[[ Variables ]]

	--[[ Services ]]

	local ChangeHistoryService = game:GetService("ChangeHistoryService")
	local Selection = game:GetService("Selection")

	local CoreGui = game:GetService("CoreGui")
	local RunService = game:GetService("RunService")

	--[[ Numbers ]]

	local Buttons = 0
	local DockWidgets = 0


	--[[ Stings ]]

	local ButtonString = 'Button_'
	local DockWidgetString = 'DockWidget_'

	--[[ Bools ]]

	local TestingMode = false
	local IsToolbar = false
	local CallSelection = true
	local SetToNil = true

	--[[ Instances ]]

	local PluginGui = nil
	local PrevPluginGui
	
	--[[ Tables ]]

	local PluginGuiInside = {}
	local GUIs = {}

	--[[ Important! ]]

	local Plugin_ = nil
	local Toolbar = nil
	
	--[[ Settings ]]

	local Settings = nil

--[[ Local Functions ]]

local function ErrorOutput (Warning: string)
	--
	if tostring(Warning) ~= nil and TestingMode == true then
		warn(Warning)
		--
	end
end

local function CheckPlugin ()
	if Plugin_ == nil then ErrorOutput('Please set the "Plugin" Variable with ":SetDefaults".') return false end
end

local function CheckGui ()
	local Gui = CoreGui:FindFirstChild("PluginGui")
	--
	if CoreGui:FindFirstChild("PluginGui") then
		--
		PrevPluginGui = PluginGui
		--
	elseif PrevPluginGui ~= nil then
		--
		local Clone = PrevPluginGui:Clone()
		Clone.Parent = CoreGui
		--
	else
		PluginGui = Instance.new("ScreenGui", CoreGui)
		PluginGui.Name = "PluginGui"
		PluginGui.Archivable = false
		PluginGui.IgnoreGuiInset = true
	end
	--
	PrevPluginGui = PluginGui
end

local FirstError = true

local function RunningError ()
	if FirstError then
		--
		FirstError = false
		ErrorOutput('Game is currently running. Please stop the game for testing.')
		--
	else
		task.delay(10, function()
			FirstError = true
		end)
	end
end

--[[ Check Functions ]]

function PluginService:CheckRunning ()
	if RunService:IsRunning() == true and RunService:IsClient() == true then
		RunningError()
		
		for index, gui in pairs(GUIs) do
			--
			gui:SetAttribute("PrevEnabled", gui["Enabled"])
			--
			gui["Enabled"] = false
		end
		
		return true
	else
		for index, gui in pairs(GUIs) do
			gui.Enabled = gui:GetAttribute("PrevEnabled")
		end
	end
end

--[[ Default Fuctions ]]

function PluginService:SetDefaults (Plugin: any, ButtonID: string, DockWidgetID: string, Testing: boolean)
	--
	local Same = false
	--
	if DockWidgetID == ButtonID then Same = true end
	--
	if Plugin ~= nil then Plugin_ = Plugin Settings = Plugin_:GetSetting("Settings") end
	if Testing ~= nil then TestingMode = Testing end
	--
	--
	if not Same then
		
		if DockWidgetID ~= nil then DockWidgetString = DockWidgetID
		end
		--
		if ButtonID ~= nil then ButtonString = ButtonID
		end
	end
	--
	if SetToNil then Plugin_:SetSetting("Settings", nil)
	if Plugin_ ~= nil and Plugin_:GetSetting("Settings") == nil then if not SetToNil then Plugin_:SetSetting("Settings", {}) end end
	--
	--
end

--[[ Create Functions ]]

function PluginService:CreateToolbar (Name: string)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if CheckPlugin() == false then return nil end
	if IsToolbar then ErrorOutput("Can't create Toolbar, Toolbar aready exists") return nil end
	--
	--
	local NewToolbar = Plugin_:CreateToolbar(Name)
	--
	Toolbar = NewToolbar
	IsToolbar = true
	--
	return NewToolbar
end


function PluginService:CreateButton (Tooltip: string, ImageID: number, DisplayName: string)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if CheckPlugin() == false then return nil end
	if tostring(DisplayName) == nil or tostring(Tooltip) == nil then ErrorOutput('') return nil end
	--
	Buttons += 1
	local NewButton = Toolbar:CreateButton("Button_" .. tostring(Buttons), Tooltip, "rbxassetid://" .. tostring(ImageID), DisplayName)
	--
	return NewButton
end


function PluginService:CreateDockWidget (Title: string, DockWidgetInfo: Enum.DockWidgetPluginGuiInfo, Enabled: boolean)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if CheckPlugin() == false then return nil end
	--
	if DockWidgetInfo == nil then ErrorOutput('Please provide a correct "Enum.DockWidgetPluginGuiInfo".') return nil end
	if tostring(Title) == nil then Title = "" end
	--
	DockWidgets += 1
	--
	local NewGui = Plugin_:CreateDockWidgetPluginGui(DockWidgetString .. tostring(DockWidgets), DockWidgetInfo)
	NewGui.Title = Title
	NewGui.Archivable = false
	--
	table.insert(GUIs, NewGui)
	--
	if Enabled ~= nil then
		NewGui.Enabled = Enabled
	end
	--
	return NewGui
end



--[[ Misc. Functions ]]


function PluginService.SetWaypoint (Name: string)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if tostring(Name) ~= nil then
		ChangeHistoryService:SetWaypoint(Name)
	end
end

function PluginService.FilterTableForInstance (Table: {Instance}, IsAName: string)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if Table == nil or IsAName == nil or tostring(IsAName) == nil then return nil end
	--
	local FilteredTable = {}
	--
	for index, value in pairs(Table) do
		if value:IsA(IsAName) then
			--
			table.insert(FilteredTable, value)
		end
	end
	--
	return FilteredTable
end

function PluginService.FilterTableForName (Table: {Instance}, Name: string)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if Table == nil or Name == nil or tostring(Name) == nil then return nil end
	--
	local FilteredTable = {}
	--
	for index, value in pairs(Table) do
		if value["Name"] == Name then
			--
			table.insert(FilteredTable, value)
		end
	end
	--
	return FilteredTable
end


--[[ Plugin Settings ]]

function PluginService.RetreiveSetting (Name: string, Scope: string)
	--
	Name = tostring(Name)
	Scope = tostring(Scope)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if CheckPlugin() == false then return nil end
	if Name == nil then ErrorOutput('Please set a Name for the the "RetreiveSetting" function.') return nil end
	--
	local Value = Settings[Name]
	--
	if Scope ~= nil and Scope ~= "" then Value = Value[Scope] end
	--
	return Value
end

function PluginService.ConfigureSetting (Name: string, Scope: string, Value: any)
	--
	Name = tostring(Name)
	Scope = tostring(Scope)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if CheckPlugin() == false then return nil end
	if Name == nil then ErrorOutput('Please set a Name for the the "ConfigureSetting" function.') return nil end
	--
	local Settings = Plugin_:GetSetting("Settings")
	local NewTable = Settings
	--
	local TableValue = NewTable[Name]
	--
	if Scope ~= nil and Scope ~= "" then TableValue = TableValue[Scope] end
	--
	TableValue = Value
	--
	Plugin_:SetSetting("Settings", NewTable)
	--
	return Value
end

function PluginService.DeleteSetting (Name: string, Scope: string)
	--
	Name = tostring(Name)
	Scope = tostring(Scope)
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if CheckPlugin() == false then return nil end
	if Name == nil then ErrorOutput('Please set a Name for the the "RetreiveSetting" function.') return nil end
	--
	--
	local Settings = Plugin_:GetSetting("Settings")
	local NewTable = Settings
	--
	local TableValue = NewTable[Name]
	--
	if Scope ~= nil and Scope ~= "" then TableValue = TableValue[Scope] end
	--
	TableValue = nil
	--
	Plugin_:SetSetting("Settings", NewTable)
	--
	return nil
end

function PluginService:ClearSettings (Do_It: boolean, Turn_Back: boolean, Are_You_Sure: boolean)
	if PluginService:CheckRunning() == true then return nil end
	--
	if CheckPlugin() == false then return nil end
	--
	if Do_It == true and Turn_Back == false and Are_You_Sure == true then
		Settings = nil
	end
end

function PluginService:SetSettings ()
	--
	if PluginService:CheckRunning() == true then return nil end
	--
	if CheckPlugin() == false then return nil end
	--
	if Settings:GetSetting("Settings") == nil then
		Settings = Plugin_:SetSetting("Settings", {})
	end
end


--[[ Less Important ]]



function PluginService:ActivatePlugin ()
	--
	if PluginService:CheckRunning() == true then return nil end
	if CheckPlugin() == false then return nil end
	--
	Plugin_:Activate(true)
end



--[[ Gui ]]



function PluginService.SetEnabled (Value: boolean, Gui: GuiObject)
	--
	if PluginService:CheckRunning() == true then return nil end
	if CheckPlugin() == false then return nil end
	--
	if Gui == nil then ErrorOutput('Invalid "Gui" Variable.') return nil end
	--
	if Value == nil then Value = false end
	--
	local Success, ErrorMessage = pcall(function()
		return Gui["Enabled"]
	end)
	--
	if Success then Gui["Enabled"] = Value end
	Gui:SetAttribute("PrevEnabled", Value)
	--
	return Value
end

function PluginService:AddDockingGui (Frame: Frame, Parent: Instance)
	--
	if PluginService:CheckRunning() == true then return nil end
	if CheckPlugin() == false then return nil end
	if not Frame:IsA("Frame") and not Frame:IsA("GuiLabel") and not Frame:IsA("CanvasGroup") then ErrorOutput('Invalid "Frame" Variable.') return nil end
	--
	local Clone = Frame:Clone()
	Clone.Parent = Parent
	--
	return Clone
end

function PluginService:AddGui (Gui: Frame)
	--
	if PluginService:CheckRunning() == true then return nil end
	if CheckPlugin() == false then return nil end
	if not Gui:IsA("ScreenGui") then ErrorOutput('Invalid "Gui" Variable.') return nil end
	--
	local Clone = Gui:Clone()
	Clone.Parent = CoreGui
	--
	return Clone
end

return PluginService

I sense invalid syntax if Plugin ~= nil then Plugin_ = Plugin Settings = Plugin_:GetSetting(โ€œSettingsโ€) end
in PluginService:SetDefaults

Does your script actually throw an error?

Yes it does:
Error

Can u do a slightly bigger image

Thereโ€™s just syntax errors in your code fix em
Missing end:

if SetToNil then Plugin_:SetSetting("Settings", nil)

Two statements on one line:

Plugin_ = Plugin Settings = Plugin_:GetSetting("Settings")
1 Like

Just some quick notes:

  • You should post the actual error, so itโ€™s easier to debug.
  • You should properly format your code so itโ€™s easier to read

The problem with your module is a missing โ€œendโ€ statement at the end of the file. Iโ€™d recommend using proper formatting to catch these errors in the future.

2 Likes

Thank you for the help! :happy3: sorry for any inconveniences! :ohmy:

BTW, the Script Analysis window is a great way to keep track of syntax errors and warnings while youโ€™re coding. Itโ€™s at Windows > Script > Analysis in studio for me. Check the โ€œDisplay only current scriptโ€ option and it will highlight errors and warnings in the script youโ€™re editing.

2 Likes

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