This is less of a big deal, and more of an annoyance. I'm assuming it's how I add the values into the table.
Let me try to walk you through my thinking process.
I have a folder full of checkpoints. When the player walks on these checkpoints, one of the players leaderstats, "Stage", gets updated to the number of the checkpoint.
Anyways, when the player dies I check the value of the players Stage leaderstat to the number index of a table. Here's what it looks like,
local wrk = game:GetService("Workspace")
local CheckpointsFolder = wrk:WaitForChild("Checkpoints")
local CheckpointsFolderChildren = CheckpointsFolder:GetChildren()
local Checkpoints = {}
for i,v in pairs(CheckpointsFolderChildren) do--Sorts the table
local length = tonumber(string.len(v.Name))
local num = string.sub(v.Name, 6, length)
if length and num and v then
table.insert(Checkpoints, num, v)
end
end
Yes, I know this isn't the best script ever, and there's lots of not needed stuff, but this extra stuff shouldn't be the problem, so don't worry about it unless you think it's causing my problem.
The folder looks like this,
All the code does is put all of these in a table in order.
There are 20 spawns but when I do this to check the values of the table, I get this,
for i = 1,#Checkpoints do
print(Checkpoints[i])
end
OUTPUT,
Spawn1
Spawn2
nil
Spawn3
Spawn4
Spawn5
Spawn6
Spawn7
Spawn8
Spawn9
Spawn10
Spawn11
Spawn12
Spawn13
Spawn14
Spawn15
Spawn16
Spawn17
Spawn18
Spawn19
Spawn21
Spawn20
As you can see, I get a nil value in the third spot of the table. I've done things like this in the past and the same thing always seems to happen
My question,
How should I be doing this? How should I insert the values, In order, into my table?
Here's what I've been doing to fix the problem,
for i = 1,#Checkpoints do
if not Checkpoints[i] then
table.remove(Checkpoints, i)
end
end
And this does fix the problem, and I'll be fine if I have to do this, but I was just confused as to why this is happening.
Thank you.

1 comment
Wow. Thanks a ton!