Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Trying to get data from a table but it won't work?

So the script is suppost to math.random(1, 13) and print all the data from the selected number but it's doesn't and prints table: 330306A4. Could anyone fix it?

while true do wait(10)

local songs={
	[1] = {"StarBoy ft. Daft Punk - The Weekend", 1700, 632765861},
	[2] = {"Lukas Graham - 7 years", 1000, 537540446},
	[3] = {"Lean On ft. MO (NGHTMRE Remix) - Major Lazer", 2000, 300494797},
	[4] = {"Marshmello - Ritual (feat. Wrabel)", 1300, 537601228},
	[5] = {"Alan Walker - Alone", 1000, 568037220},
	[6] = {"Twenty One Pilots - Stressed Out", 1200, 587009665},
	[7] = {"Ed Sheeran - Castle on the hill", 1000, 609948497},
	[8] = {"Twenty One Pilots - Ride", 1100, 641626045},
	[9] = {"Marshmello - Alone", 1000, 536049623},
	[10] = {"Tristam - Devotion", 900, 626935808},
	[11] = {"Luis Fonsi - Despacito ft. Daddy Yankee", 900, 792221953},
	[12] = {"Flor Rida - My House", 1050, 672143116},
	[13] = {"The White Stripes - Seven Nation Army", 300, 525963945},
}	
for i,v in pairs(songs) do
print(rawget( songs, math.random(1,13)))
end
end

1 answer

✓ Accepted answer
while true do wait(10)

local songs={
    [1] = {"StarBoy ft. Daft Punk - The Weekend", 1700, 632765861},
    [2] = {"Lukas Graham - 7 years", 1000, 537540446},
    [3] = {"Lean On ft. MO (NGHTMRE Remix) - Major Lazer", 2000, 300494797},
    [4] = {"Marshmello - Ritual (feat. Wrabel)", 1300, 537601228},
    [5] = {"Alan Walker - Alone", 1000, 568037220},
    [6] = {"Twenty One Pilots - Stressed Out", 1200, 587009665},
    [7] = {"Ed Sheeran - Castle on the hill", 1000, 609948497},
    [8] = {"Twenty One Pilots - Ride", 1100, 641626045},
    [9] = {"Marshmello - Alone", 1000, 536049623},
    [10] = {"Tristam - Devotion", 900, 626935808},
    [11] = {"Luis Fonsi - Despacito ft. Daddy Yankee", 900, 792221953},
    [12] = {"Flor Rida - My House", 1050, 672143116},
    [13] = {"The White Stripes - Seven Nation Army", 300, 525963945},
}   
for i,v in pairs(songs) do
	song=songs[math.random(13)]
	print(rawget(song,1),rawget(song,2),rawget(song,3))
end
end

Changed rawget to instead print out each value in the selected song table. Your problem is that when you select a song, it's held as a table, not a single value.

This discussion is preserved as it was. New answers, comments, and votes are closed.