Table adds extra spaces for no reason?

There is only 8 elements within this table but when printed the list goes up to 10, with 2 of the spaces being nothing.

Code: local BTT = { – Buyable trails

RedTrail = {
	"RedTrail", -- Trail Name
	"http://www.roblox.com/asset/?id=", -- Trail Image
	false,-- Owned
	1, -- Table Position
	50, -- Coin Cost
	Color3.fromRGB(255,0,0)
};
BlueTrail = {
	"BlueTrail", -- Trail Name
	"http://www.roblox.com/asset/?id=", -- Trail Image
	false, -- Owned
	2,
	50,
	Color3.fromRGB(255,0,0)
};

GreenTrail = {
	"GreenTrail", -- Trail Name
	"http://www.roblox.com/asset/?id=", -- Trail Image
	false, -- Owned
	3,
	75,
	Color3.fromRGB(0,225,0)
};

YellowTrail = {
	"YellowTrail", -- Trail Name
	"http://www.roblox.com/asset/?id=", -- Trail Image
	false, -- Owned
	4,
	75,
	Color3.fromRGB(255,255,0)
};

PinkTrail = {
	"PinkTrail", -- Trail Name
	"http://www.roblox.com/asset/?id=", -- Trail Image
	false, -- Owned
	5,
	100,
	Color3.fromRGB(255,0,255)
};

CyanTrail = {
	"CyanTrail", -- Trail Name
	"http://www.roblox.com/asset/?id=", -- Trail Image
	false, -- Owned
	6,
	100,
	Color3.fromRGB(0,255,255)
};

GoldTrail = {
	"GoldTrail", -- Trail Name
	"http://www.roblox.com/asset/?id=", -- Trail Image
	false, -- Owned
	7,
	1000,
	Color3.fromRGB(255,200,0)
};

EmeraldTrail = {
	"EmeraldTrail", -- Trail Name
	"http://www.roblox.com/asset/?id=", -- Trail Image
	false, -- Owned
	8,
	2500,
	Color3.fromRGB(0,255,55)
};

}

local STT = {} – Sorted TrailTable

for i,z in pairs(BTT) do
table.insert(STT, z[4], z)
end

print(STT)

Result:
[1] = :arrow_forward: {…},
[3] = :arrow_forward: {…},
[4] = :arrow_forward: {…},
[5] = :arrow_forward: {…},
[6] = :arrow_forward: {…},
[7] = :arrow_forward: {…},
[9] = :arrow_forward: {…},
[10] = :arrow_forward: {…}

As you can see, 2 & 8 are missing for some reason. Please help as soon as possible, I’ve been totally stumped here.

pairs and iPairs (roblox.com)
for loop - What is the difference of pairs() vs. ipairs() in Lua? - Stack Overflow

read this and you will find the problem

1 Like