Music System assistance

I’m trying to create a music system from a gui, where it clones a template and you can click on it and see the current song thats playing and who it’s by, I do understand for i loops, i’m trying to get it so when you click the button it shows that song name, id and author. The issue is the for i loops aren’t working as i can see but i have searched for almost a day and couldn’t find anything related on the dev forum and the developer hub.

local Gui = script.Parent.Parent.musicGui

-->
local Frame = Gui.Holder or script.Parent.Holder
local Holder = Frame.Plate or script.Parent.Holder.Plate
local currentFrame = script.Parent.Holder.currentSong
local Template = Holder.Template or script.Parent.Holder.Plate.Template
-->
local SongName = currentFrame.SongName
local SongID = currentFrame.SongID
local SongAuthor = currentFrame.SongAuthor
-->

local music = {
	Song1 = {{
		SongName = "Some Dance Monkey remix",
		SongId = 4532362987,
		Author = "",
	}};
	Song2 = {{
		SongName = "Nightcore Sweet but Psycho",
		SongId = 5481675798,
		Author = "",
	}};
	Song3 = {{
		SongName = "Loudness and Clarity",
		SongId = 4120614652,
		Author = "Joakim Karud",
	}};
	Song4 = {{
		SongName = "Baby I'm Yours",
		SongId = 26493104010,
		Author = "",
	}};
	Song5 = {{
		SongName = "7 Rings",
		SongId = 5624503572,
		Author = "Arianda Grande",
	}};
	Song6 = {{
		SongName = "Sunflower",
		SongId = 2723566837,
		Author = "Post Malone",
	}};
	Song7 = {{
		SongName = "Butter",
		SongId = 2203961758,
		Author = "Swiss001",
	}};
	Song8 = {{
		SongName = "Good old Days",
		SongId = 3499664079,
		Author = "Joakim Karud",};
	};
}
--[[
		local fresh = Template:Clone()
		fresh.Name = File.SongName
		fresh.Text = File.SongName
		fresh.Parent = Holder
		fresh.MouseButton1Click:Connect(function()
			SongName.Text = File.SongName
			SongID.Text = File.SongId	
			SongAuthor.Text = File.Author
		end)	
--]]


local function refresh(Sounded)
	for A,B in pairs(music) do
		for C,D in pairs(B) do
			local E = Template:Clone()
			E.Name = D.SongName
			E.Text = D.SongName
			E.Parent = Holder
			E.MouseButton1Click:Connect(function()
				SongName.Text = D.SongName
				SongID.Text = D.SongId	
				SongAuthor.Text = D.Author
			end)
		end
	end
end

refresh()

Thanks

3 Likes

The problem is that your music dictionary’s values aren’t dictionaries themselves but dictionaries in arrays. This is because you’ve got 2 braces on either side causing it to be a dictionary in an array henceforth B[1] is your dictionary you want.

You may either solve this by iterating over B[1] in your for loop or by removing a pair braces on each song:

local music = {
	Song1 = {
		SongName = "Some Dance Monkey remix",
		SongId = 4532362987,
		Author = "",
	};
        --// Etc
};
2 Likes

Thank you! This helped alot, i have just tested it and works perfecto!

1 Like

Yeah whenever i modify the code to the part you’ve said to do, it’s giving me this error: Screenshot 2020-09-23 at 4.57.08 pm

Try using next.

for A, B in next, music do
   ---  Code here ---
end

This will allow you to loop through your dictionary with ease!

@frriend, thank you so much! that helped and fixed the code!

1 Like