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
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
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
Mystxry12
(Mystxry)
July 12, 2023, 10:01am
#11
That’s weird, can you send an ss of the whole script?
Mystxry12
(Mystxry)
July 12, 2023, 10:04am
#13
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
Mystxry12
(Mystxry)
July 12, 2023, 10:10am
#15
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?
Mystxry12
(Mystxry)
July 12, 2023, 10:17am
#17
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…
Mystxry12
(Mystxry)
July 12, 2023, 10:18am
#19
Oh so it was a studio bug, anyways glad to see it fixed