ServerScriptService.MenuModule.CharacterButtons:31: attempt to index nil with 'Initilize'

Hi, I am an amateur at using module scripts but I know some knowledge on it.

I have a module component called CharacterButtons which handles the buttons of a certain gridlayout frame.

Inside the module script I try to REQUIRE another module script that will handle changing the player and etc. Now the error occurs.

Heres the component where I try to require another module and it fails:

--] Variables
local SoundsFolder = script.Parent.Sounds
local Debris = game:GetService("Debris")
local TweenService = game:GetService("TweenService")
local MenuModule = require(game:GetService("ServerScriptService").MenuModule)
local SelectionModule = require(game:GetService("ServerScriptService").SelectionModule)
-- This code is so messy cuz I don't usually work with ui components.
local Menu = {}
Menu.__index = Menu
function Menu.new(player,ui)
	local self = setmetatable({},Menu)
	self.Player = player
	self.Instance = ui
	return self
end

function Menu:Initilize()
	Menu.ButtonFolders = {
		CharacterGrid = self.Instance.Selection.SelectionFrame.CharacterFrame.CharacterGrid	
	}
	
	for _,frame in ipairs(Menu.ButtonFolders.CharacterGrid:GetChildren()) do
		if frame:IsA("Frame") then
			for _,button in ipairs(frame:GetChildren()) do
				if button:IsA("ImageButton") then
					button.MouseButton1Click:Connect(function()
						if self.Player:FindFirstChild("Information").HasCharacter.Value == false then
							self.Player.Information.HasCharacter.Value = true
							local Character = button.Parent.Name
							local selection = SelectionModule.new(self.Player,Character)
							selection:Initilize() -- this is where the issue starts
							button.TextLabel.Text = "Selected"
							for i,v in ipairs(button:GetChildren()) do
								if v:IsA("UIGradient") then
									v:Destroy()
								end
							end
							script.Red:Clone().Parent = button
						end
					end)
				end
			end
		end
	end
end


function Menu:UnselectCharacter()
	
end

function Menu:ShowClassInfo()
	
end

return Menu

Can you show your selectionmodule?

It’s unfinished.

--] Variables

local Characters = game:GetService("ServerStorage").Characters

local Classes = game:GetService("ServerScriptService").Classes

local Selection = {}

Selection.__index = Selection

function Selection.new(Player,Selected)

local self = setmetatable({},Selection)

self.Player = Player

self.PlayerUI = Player.PlayerGui:FindFirstChild("Menu").Selection.SelectionFrame

self.Selection = Selected

end

function Selection:Initilize()

print("Player's Class: ", self.Selection)

end

function Selection:Unselect()

end

return Selection

You’re never returning anything in Selection.new, typically constructors return the created object, so you’d just return self at the end of the function

Oh I see, I forgot to return self. That’s very small thank you very much

1 Like

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