Help With Counting Tables Inside Module Script

Hello, I Was Trying To Create Function Inside Module Script That Counts How Much Song Is Inside Table But I Am Getting Error: attempt to call missing method ‘Count’ of table

Here Is Code:

local Songs = {
	[1] = {
		Name = "Song Name 1",
		Composer = "Composer Name 1",
		Genre = "Genre 1",
		ID = "rbxassetid://0"
	},

	[2] = {
		Name = "Song Name 2",
		Composer = "Random Dude",
		Genre = "Unknown",
		ID = "rbxassetid://0"
	},
}

function Songs:Count()
	local Count = 0
	for i,v in pairs(Songs) do
		Count += 1
	end
end

return Songs
4 Likes

Can you show the code that calls :Count()? Also you don’t need to loop through everything, just do:

function Songs:Count()
	return #Songs
end
3 Likes

Not Implemented Yet But Im Using Command Bar With This Command

require(game.ServerScriptService.Music.Songs):Count()
1 Like

Still Same Error :slightly_frowning_face:

require(game.ServerScriptService.Music.Songs):Count():1: attempt to call missing method 'Count' of table
1 Like
local Songs = {}
Songs.Songs = {
	[1] = {
		Name = "Song Name 1",
		Composer = "Composer Name 1",
		Genre = "Genre 1",
		ID = "rbxassetid://0"
	},

	[2] = {
		Name = "Song Name 2",
		Composer = "Random Dude",
		Genre = "Unknown",
		ID = "rbxassetid://0"
	},
}

function Songs:Count()
	return #self.Songs
end

return Songs
2 Likes

nope it’s not working…

1231323132131321 dont mind the numbers xd

Weird, try this?

local Songs = {}
Songs.Songs = {
	[1] = {
		Name = "Song Name 1",
		Composer = "Composer Name 1",
		Genre = "Genre 1",
		ID = "rbxassetid://0"
	},

	[2] = {
		Name = "Song Name 2",
		Composer = "Random Dude",
		Genre = "Unknown",
		ID = "rbxassetid://0"
	},
}

function Songs.Count()
	return #Songs.Songs
end

return Songs
1 Like

nope still same error

12313213131313

print(require(game.ServerScriptService.Music.Songs))

Run this in command bar

02:59:36.592  > print(require(game.ServerScriptService.Music.Songs))  -  Studio
  02:59:36.593   ▼  {
                    [1] =  ▶ {...},
                    [2] =  ▶ {...}
                 }  -  Edit

That’s weird, can you send an ss of the whole script?

The method name is CountSongs… So do

require(game.ServerScriptService.Music.Songs):CountSongs()

require(game.ServerScriptService.Music.Songs):CountSongs()
:1: attempt to call missing method ‘CountSongs’ of table

Can you print the table again but this time expand the subtables and show me the output?

FYI, I srsly dunno why this aint working

OHHHH I get it now… I Think It’s Roblox Bug Cuz When i checked the printed tables The values Were Old. I Saved Script And Then Tried It Again But Still Got old output. Maybe Restart Could Help?

Seems like you are in team create, so are you committing the scripts? Maybe that’s the issue idk

i restarted the studio and it printed the new output…

Oh so it was a studio bug, anyways glad to see it fixed

i still get error :frowning:

safdsadad1321321