I am trying to change the parts brickcolor in order by looping through the children. I have 1 problem, why does the output print “ran first” last and “ran 2nd” first? Code:
local Model = workspace.Model
--k = 1, 2, 3, 4
--#children = 4
--v = 2, 3, 4, 1
--k - v.Value = 1
--1, 2, 3, 4
--4, 3, 2, 1
fi = 0 -- first index [fi = k]
for k, v in ipairs(Model:GetChildren()) do
if Model[v.Name].pos.Value > k then
test = Model[v.Name].pos.Value / k * k
if math.abs(tonumber(k) - Model[v.Name].pos.Value) < k then
local add = Model[v.Name].pos.Value + tonumber(k) - k --3, 4
if Model[v.Name].pos.Value < #Model:GetChildren() then
Model[v.Name].BrickColor = BrickColor.Black()
print('3rd')
else
Model[v.Name].BrickColor = BrickColor.Black()
print('4th')
end
else
--2nd
Model[v.Name].BrickColor = BrickColor.Black()
print("ran 2nd")
end
else
--1st
Model[v.Name].BrickColor = BrickColor.Black()
print("ran first")
end
end