I’m trying to make a script that regenerates a tile of snow (there is a collection of snow tiles) like this:
Hierarchy on right side:
This is the script I’ve tried so far. I can’t figure out how to see if there is a missing layer, and then replace that missing layer with a new snow layer.
Script (Server of course):
while task.wait(5) do
for _, tile in pairs(script.Parent:GetChildren()) do
if tile.Name ~= script.Parent.Name then
for i, v in ipairs(tile:GetChildren()) do
if string.match(v.Name, 'Layer') then
if v.Name ~= 'Layer1' and not tile:FindFirstChild('Layer'.. tostring(tonumber(string.sub(v.Name, #v.Name)) - 1)) then
local newLayer = game.ReplicatedStorage.TileTemplate['Layer'.. tostring(tonumber(string.sub(v.Name, #v.Name)) - 1)]:Clone()
newLayer.Parent = tile
newLayer.Position = v.Position + Vector3.new(0, 1, 0)
newLayer.BrickColor = BrickColor.Red() -- for testing purposes then
print('regenerated')
end
end
end
end
task.wait(2)
end
end
All help appreciated! Thanks! 


