I have a piece of code which will insert things into a table based on two numbers inside of a module script, however whenever I try to put something in the 4th place, suddenly it breaks and causes extra nil values specifically in index 2 or 3 at random. It is running on a local script.
repeat
task.wait()
until game:IsLoaded()
Players = game:GetService(“Players”)
player = Players.LocalPlayer
gui = player.PlayerGui.Menu
guiScroll = gui.Frame.SongScroll
ReplicatedStorage = game:GetService(“ReplicatedStorage”)
ReplMisc = ReplicatedStorage.Misc
songButton = ReplMisc.SongButton
events = ReplicatedStorage.Events
menuFolder = workspace.Menu
selectFolder = menuFolder.SongSelect
songList = {
}
buttonDist = 0.06
–gui.Enabled = true
local start = selectFolder.Start:WaitForChild(“Ground”)
local startingPoint = start
for i,chart in ipairs(ReplicatedStorage.Charts:GetChildren()) do
local chartModule = require(chart)
if songList[chartModule.setlist] == nil then
songList[chartModule.setlist] = {}
end
table.insert(songList[chartModule.setlist],chartModule.position,chart)
end
4 songs in each setlist, when I remove the 4th song in each it works fine, and when I change the position in the 4th song to 5 it also works fine. I am so confused.
output that’s “fixed” (when chartModule.position = 4):
weird output (when chartModule.position = 4):