local songs = {}
for i, song in pairs(Group:GetChildren()) do
table.insert (songs, song)
end
local CurrentSound = next(songs, nil)
Skip.MouseButton1Click:Connect(function()
CurrentSound.Playing = false
next(songs,CurrentSound).Playing = true
end)
currentSound is a sound, not an index, thats the issue
Only used it once but as I remember next returns index and value, so you are using it wrong. And i think next does not go to start (index 1), if there is no next indeces
My apologies. I’m not sure if it will work, that’s why I asked you to try it. The error seems to be that by doing CurrentSound = songs[1], the variable CurrentSound doesn’t equal to the index of the song[1] but rather the value of the table entry with the index[1]. You get the index of the first table entry by doing next(tableName, nil). Then, you can use next over and over to move down the table and cycle all of the songs.
the next() function is recognised now, but the properties cannot be set on the sound because the index is only a number. How do i get the corresponding instance from the index to change the properties?
Perhaps you could loop through all of the sounds until the value (name) of the currentSound is equal to the name of the sound from the soundgroup, and then set .Playing to be true.
local songs = {}
for i, song in pairs(Group:GetChildren()) do
table.insert (songs, song)
end
local CurrentSound = next(songs, nil)
Skip.MouseButton1Click:Connect(function()
for i, song in pairs(Group:GetChildren()) do
if song.Name == songs[CurrentSound]) then
song.Playing = true
break
end
end
end)
I apologize for “spoonfeeding” you the code but it is much easier to explain this way, you do not have to use it and again, I am not sure if it works. Feel free to ask me questions about any part of the code and I’ll gladly explain it to the best of my ability.
Prints are your friend! Can you try adding a print within the if statement like print(song.Name) and also try changing song.Playing = true to song[“Playing”] = true
I might have something wrong in the above code, because im a bit unfamiliar with the next statement, however, this will do what you want, it will move the index until the end and then repeat
local songs = Group:GetChildren()
local SoundIndex = 1
local CurrentSound = songs[SoundIndex]
Skip.MouseButton1Click:Connect(function()
CurrentSound.Playing = false
SoundIndex %= #songs + 1
CurrentSound = songs[SoundIndex]
CurrentSound.Playing = true
end)
% is the modulus operator, you can see where someone needed help with it here, and gets a good explaination
But in our case, basically, if you have a list of songs 1 through 10
every time we do index %= 10, our index will stay the same (not counting the +1 we add to it), until it gets to 10, then that line will set it back to 0 (with the +1 starting it at 1) (and the + 1 at the end is to make it keep moving forward)
So basically our index will go 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, etc…
The reason its not stopping is because (and I think someone else mentioned it above) you can’t set the Playing = true and Playing = false, those can only be read from, not written to.
you have to do CurrentSound:Play()
and CurrentSound:Stop()