Help With Counting Tables Inside Module Script

:skull: what’s it say this time lol?

its the same:

require(game.ServerScriptService.Music.Songs):CountSongs():1: attempt to call missing method 'CountSongs' of table  -  Edit
  03:19:45.810  Stack Begin  -  Studio
  03:19:45.810  Script 'require(game.ServerScriptService.Music.Songs):CountSongs()', Line 1  -  Studio
  03:19:45.810  Stack End  -  Studio

Dk if this helps, but go to View tab, hover over the buttons till you see Drafts, then click it. It will open up a window from which you can commit all your scripts.

u mean script recovery button?

there is not such “draft” thing in my studio lol

No…

i think you use old studio cuz icons are different in mine

I took the ss from the docs so yea not the most up to date one :frowning:

oh k. but there is no such thing in my studio :sob:

Uk what test the module in game, idk call it in a script or local script and check if the method calls.

Requested module experienced an error while loading  -  Server - Music:5

aint no way :sob:, anything else with the output, also print the module jus to make sure it aint the previous copy.

i changed the function to print(“Test!”) and it worked but when i try to use function to count it gets errors

try to add the function like this

function Songs.CountSongs()
end

return Songs

and call it like this

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

There’s no point in a count function; the ‘#’ operator would do just fine.
It can be implemented if you insist, though:
Module:

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

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

function Songs:Count()
	return #self	
end

return Songs

Example usage:

local Songs = require(PATH TO MODULE HERE)
print(#Songs) --> 2
print(Songs:Count()) --> 2
1 Like

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