I have a model with bricks named as numbers like so (1-5 not in order on purpose)
-----------------Model
--------------2
--Decal
--------------3
--Decal
--------------1
--Decal
--------------4
--Decal
--------------5
--Decal
Don't worry too much about the code being correct, is just that Roblox keeps giving me
"attempt to index field 'Decal' (a nil value)" for line 9. Why is it doing this?
local chosenTexture = game.Workspace.ReferenceDecal
local model = game.Workspace.Board:GetChildren()
for i, v in pairs(model) do
local decal = v:FindFirstChild("Decal")
if decal then
if decal.Texture == chosenTexture.Texture then
v.Decal.Texture = "" ---Moves the decal in current brick to next in ascending order
local nextBrick = v.Name + z ---Ik I am adding a string to int but it works
local decalPlaceHolder = tostring(nextBrick).Decal.Texture
game.Workspace.Board.tostring(nextBrick).Decal.Texture = "decalPlaceHolder"
end
end
end

4 comments
You're trying to retrieve a decal from a number value. (5.Decal.Texture) lol
That's a typo on here, if you had read I am asking about specifically number 9, why doesn't that work? nextBrick is being converted into a string so shouldn't that work?
No, you're trying to retrieve an object from a number, not an object; it's like saying "i iz string".Parent = nil. However, you could use the FindFirstChild function again to try and find it by the number if the name's a number, or get the position from a table from the parent object. (obj:GetChildren()[Number])
I am not folllowing, sorry. So, is it line 9 where my issue is at? My thinking is, v.Name + z turns into a number because Roblox recognizes what I want to do. Then I change it to a string so I can navigate for example, 3.Decal.Texture but its doing nextBrick.Decal.Texture instead. So you recommend using FindFirstChild? How though? I do not understand. FindFirstChild("3") if the line V.name + z = 3