Instance turns into a table when using it with a module script

I want that it stays as an Instance and not a table, how do I achieve this?

The issue is that if I use a function from a module script and I need an Instance to execute the full function, I gave an Instance, but it turned into a table that contains all functions of my module script.

I looked for solutions, but couldn’t find any.
Script where I used the module script:

local lib = require(game.ReplicatedStorage["Testing Purposes"])

local screenGUI = lib.createScreenGUI(game.Players.LocalPlayer, "Testing GUI")

print(lib.screenGUI)

--local mainGUI = lib:createMainMenu(game.Players.LocalPlayer["Testing GUI"], UDim2.new(0, 285, 0, 267), UDim2.new(0, 285, 0, 267), "Main", "DracoLib Testing", Color3.fromRGB(0, 234, 255), Color3.fromRGB(72, 72, 72))

lib:testing(lib.screenGUI)

module script:

local module = {}
local screenGUI
module.createScreenGUI = function(parent, name)
	local ScreenGui = Instance.new("ScreenGui", parent)
	ScreenGui.Name = name
	ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
	module.screenGUI = ScreenGui
	screenGUI = ScreenGui
	return ScreenGui
end

module.createMainMenu = function(parent, position, scale, name, title, titleColor, color)
	local Main = Instance.new("Frame")
	Main.Name = "Main"
	Main.Parent = screenGUI
	Main.BackgroundColor3 = color
	Main.Position = position
	Main.Size = scale
	Main.Active = true
	Main.Draggable = true
	Main.Visible = true
	
	
	if title == nil then
		module.mainMenu = Main
		return Main
	end
	local TitleHolderMain = Instance.new("Frame", module.mainMenu)
	TitleHolderMain.Name = "TitleHolderMain"
	TitleHolderMain.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
	TitleHolderMain.Size = UDim2.new(position.X.Scale, position.X.Offset, 0, 25)
	
	module.mainMenuTitleHolder = TitleHolderMain
	
	local TitelMain = Instance.new("TextLabel", TitleHolderMain)
	TitelMain.Name = "TitelMain"
	TitelMain.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
	TitelMain.BackgroundTransparency = 1.000
	TitelMain.Position = UDim2.new(0.147368416, 0, 0, 0)
	TitelMain.Size = UDim2.new(0, 200, 0, 25)
	TitelMain.Font = Enum.Font.SourceSans
	TitelMain.Text = title
	TitelMain.TextScaled = true
	TitelMain.TextSize = 14.000
	TitelMain.TextWrapped = true
	if titleColor then
		TitelMain.TextColor3 = Color3.fromRGB(0, 211, 230)
	end
	
	return Main
end

module.testing = function(parent2) --used this function
	print(parent2)
end
return module

printed output: (for module.testing)
{
[“createMainMenu”] = “function”,
[“createScreenGUI”] = “function”,
[“screenGUI”] = Testing GUI,
[“testing”] = “function”
}

The problem is that you used a colon operator instead of a dot operator.

lib:testing(lib.screenGUI) is the same as lib.testing(lib, lib.screenGUI)

Because you used a colon operator, the first parameter in the function will be the module itself, which is why the function printed out the module.

2 Likes

ooh, didnt know that! Thanks for telling me :slight_smile:

so how do I need to do it? kinda confused. i did this:
lib:testing(lib, lib.screenGUI)

nvm finally understanded it :slight_smile: thank you

1 Like

lib.testing(lib.screenGUI)

For anyone who reads this thread.