So I'm working with datastore and saving an array called colourtable, it is supposed to store a list of integers that represent the character parts' colours. I take the colour of the part, compare it to my preset colours and then save that integer in the array based on what the name of the part is. In the loading script I colour the part again with the same index at which I saved that parts' colour. All of this has been working perfectly so far, however, the 'Head' randomly does not save properly and when I printed colourtable, expecting to see a list of 1s, the second index was just nil. There is nothing different about the head from any of the other parts and the script is entirely identical.
I wonder if there is some information about Arrays that I am just missing, why is the second element just always nil? Trouble shooting hasn't gotten me anywhere, could someone explain why this is happening or perhaps suggest a workaround
This is in the saving script
local loop = player.Character:GetChildren() colourtable = {} for i=1, #loop do if loop[i].ClassName == 'MeshPart' then local data = loop[i].Color if data == Color3.fromRGB(25,21,39) then if loop[i].Name == 'Head' then table.insert(colourtable,2,1) end end end end
This is in the loading script
if colourtable[2] == 1 then player.Character.Head.Color = Color3.fromRGB(25,21,39)
Here I'm trying to put the integer 1 into the second element of the array if the objects name is Head and if the colour matches that preset color3. This script works for every other part except head and FR_LegTop, neither of which have anything different to any other part in script or in their properties.