local currentIndex = 1
local function onInputBegan(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.RightBracket then
currentIndex += 1
if currentIndex > 10 then
currentIndex = 1
end
track.SoundId = snd[currentIndex].id
track:Play()
end
end
to be honest i am not really sure you need to use a for loop for that
local soundToPlay = 0
local function OnInputBegan(input, gameProcessed)
if gameProcessed then
return
end
if input.KeyCode == Enum.KeyCode.RightBracket then
soundToPlay += 1
if soundToPlay > #snds then
soundToPlay = 1
end
local info = string.match(track.SoundId, "%d+")
track.SoundId = snds[soundToPlay].id
track:Play()
end
end
Use an upvalue/non-local variable to log which song to play, increment its value by 1 each time the button is pressed then reset it back when the last song in the table is reached , remember to use the “gameProcessed” parameter to ignore user inputs which were in relation to the core features of the game (chat for example).