When I try removing the ChosenSong and FakeChosenSong values they print as nil but are used multiple times and they print at the bottom normally. So they don't actually get removed and im not sure what is causing this.
Output GIF: https://gyazo.com/970ecb14b8aa72e84e72ec97010b14ff
01 | songs = { 461736208 , 438917260 , 516046263 , 506212392 } |
02 |
03 | boards = workspace.Boards |
04 |
05 | while true do |
06 |
07 | chosensong = songs [ math.random( 1 ,#songs) ] --Choses a random ID from songs list |
08 | chosenboard = math.random( 1 , 4 ) --Selects random board |
09 | for i = 1 , 4 do |
10 | if i = = chosenboard then |
11 | local songname = game:GetService( "MarketplaceService" ):GetProductInfo(chosensong) --Gets the asset name from ID |
12 | boards:FindFirstChild( "Board" ..i):WaitForChild( "SurfaceGui" ):WaitForChild( "SongChoice" ).Text = tostring (songname.Name) --Places chosen song on boards |
13 | table.remove(songs, chosensong) |
14 | print (songs [ chosensong ] ) |
15 | else |
Ok, so, lets start with Line 7
1 | chosensong = songs [ math.random( 1 ,#songs) ] |
This is giving you the number ID for the game to identify/play, not the index number of it. I advise you do something along the lines of
1 | chosensongno = math.random( 1 ,#songs) |
2 | chosensong = songs [ chosensongno ] |
Next part is Line 13
1 | table.remove(songs, chosensong) |
This is trying to remove a value from the table which does not exist, this is where you would use the value 'chosensongno' making it
1 | table.remove(songs, chosensongno) |
You would need to repeat this same process for the fake songs aswell, hope this helps.
table.remove(table,position)
removes whatever item is at the position.
Therefore, table.remove(table,object)
will not work.
Example:
1 | local songs = { 1000 , 2000 , 3000 } |
2 | table.remove(songs, 3 ) --Removes 3000 from the table. |
3 | table.remove(songs, 2000 ) --This will NOT remove 2000 from the table, since it tries to remove the 2000th item in the table, not the number 2000. |
4 | print (songs [ 1 ] ) --Prints 1000. |
5 | print (songs [ 2 ] ) --Prints 2000. |