local ammount = table.getn(script.Parent:GetDescendants())
local serverReady = game.ReplicatedStorage.Events.ServerReady
print(ammount)

for i, part in pairs(script.Parent:GetDescendants()) do
	spawn(function()
		if part:IsA("BasePart") then
			local safe = false
			for _, child in pairs(part:GetChildren()) do
				if child.Name == "AgeIgnore" then
					safe = true
				end
			end
			if safe == false then
				local as = game.ServerStorage.AgeScript:Clone()
				local link = Instance.new("ObjectValue")
				link.Value = script.Parent.Parent
				link.Name = "link"
				link.Parent = as

				local currentAge = Instance.new("IntValue")
				currentAge.Parent = as
				currentAge.Name = "currentAge"

				local endColor = Instance.new("Color3Value")
				endColor.Parent = as
				endColor.Name = "endColor"
				endColor.Value = Color3.fromRGB(143, 76, 42)

				local midColor = Instance.new("Color3Value")
				midColor.Parent = as
				midColor.Name = "midColor"

				local endMaterial = Instance.new("StringValue")
				endMaterial.Parent = as
				endMaterial.Name = "endMaterial"
				endMaterial.Value = "CorrodedMetal"

				local ageTillMidColor = Instance.new("IntValue")
				ageTillMidColor.Parent = as
				ageTillMidColor.Name = "ageTillMidColor"

				local ageTillEndColor = Instance.new("IntValue")
				ageTillEndColor.Parent = as
				ageTillEndColor.Name = "ageTillEndColor"

				local ageTillEndMaterial = Instance.new("IntValue")
				ageTillEndMaterial.Parent = as
				ageTillEndMaterial.Name = "ageTillEndMaterial"

				local ageTillDeadChildren = Instance.new("IntValue")
				ageTillDeadChildren.Parent = as
				ageTillDeadChildren.Name = "ageTillDeadChildren"

				local ageTillDestroy = Instance.new("IntValue")
				ageTillDestroy.Parent = as
				ageTillDestroy.Name = "ageTillDestroy"


				local strength = math.random(5, 13)
				strength = strength / 9

				strength = strength + math.min(1, part.Size.X * part.Size.Y * part.Size.Z / 50)

				local startMaterial = part.Material
				if startMaterial == Enum.Material.Grass then
					strength = strength / 5
					endMaterial.Value = "Slate"
					midColor.Value = Color3.fromRGB(193, 190, 66)
					endColor.Value = Color3.fromRGB(160, 132, 79)

				elseif startMaterial == Enum.Material.Concrete then
					strength = strength * 5
					endColor.Value = Color3.fromRGB(99, 95, 98)
					endMaterial.Value = "Slate"

				elseif startMaterial == Enum.Material.Wood then
					strength = strength * 2
					endColor.Value = Color3.fromRGB(188, 155, 93)
					endMaterial.Value = "Slate"

				elseif startMaterial == Enum.Material.WoodPlanks then
					strength = strength * 1.5
					endColor.Value = Color3.fromRGB(160, 132, 79)
					midColor.Value = Color3.fromRGB(160, 95, 53)
					endMaterial.Value = "Marble"

				elseif startMaterial == Enum.Material.Brick then
					strength = strength * 4
					endColor.Value = Color3.fromRGB(105, 102, 92)
					endMaterial.Value = "Pebble"
				end

				ageTillMidColor.Value = math.random(20, 40) * strength
				ageTillEndColor.Value = math.random(ageTillMidColor.Value + 20, ageTillMidColor.Value + 50) --*strength
				ageTillEndMaterial.Value = math.random(ageTillEndColor.Value + 30, ageTillEndColor.Value + 60) --*strength
				ageTillDeadChildren.Value = math.random(ageTillEndMaterial.Value + 30, ageTillEndMaterial.Value + 70) --*strength
				ageTillDestroy.Value = math.random(ageTillDeadChildren.Value + 20, ageTillDeadChildren.Value + 70) --*strength


				as.Parent = part
				as.Disabled = false
			end
		end
	end)
	wait()
	if i % 10 == 0 then
		serverReady:FireAllClients(i / ammount)
	end
end
serverReady:FireAllClients(1)
script.Disabled = true
