I’m making system which will look how much terraformers on planet is, and than more terraformers on planet is than faster color change tween is but the problem is it checks if previous planet was the planet that is right now and if its the other one planet then the script won’t just work for it, and will only work for the first planet. but i want to make it save how much on each planet there is terraformers. how would i make that in an easy way?
Full Script
local CelestialTerraformers = script.Parent.Parent:FindFirstChild("CelestialTerraformers")
local TweenService = game:GetService("TweenService")
local PreviousPlanet = nil
local TerraformersOnPlanet = 0
function ChildAdded()
for i, Terraformer in pairs(CelestialTerraformers:GetChildren()) do
if Terraformer:IsA("Model") and Terraformer:FindFirstChild("Active").Value == false then
for i, Interactables in pairs(Terraformer:GetChildren()) do
if Interactables.Name == "Interactables" then
local Button = Interactables:FindFirstChild("Button")
local Screen = Interactables:FindFirstChild("Screen")
local Sound = Interactables:FindFirstChild("OxygenEffectPart"):FindFirstChild("Sound")
local ClickDetector = Button:FindFirstChild("ClickDetector")
if ClickDetector:IsA("ClickDetector") then
ClickDetector.MouseClick:Connect(function()
Terraformer:FindFirstChild("Active").Value = true
ClickDetector.MaxActivationDistance = 0
local TextLabel = Screen:FindFirstChild("SurfaceGui"):FindFirstChild("TextLabel")
if TextLabel:IsA("TextLabel") then
TextLabel.Text = "Preparing For Celestial Innovations OS Activation.."
Button.Color = Color3.fromRGB(255, 133, 51)
wait(1)
TextLabel.Text = "Preparing For Celestial Innovations OS Activation..."
wait(1)
TextLabel.Text = "Preparing For Celestial Innovations OS Activation.."
wait(1)
TextLabel.Text = "Preparing For Celestial Innovations OS Activation..."
wait(1)
TextLabel.Text = "Preparing For Celestial Innovations OS Activation.."
wait(1)
TextLabel.Text = "Activating Terraforming Protocol."
Sound:Play()
wait(1)
TextLabel.Text = "Activating Terraforming Protocol.."
Sound.Volume = 0.2
wait(1)
TextLabel.Text = "Activating Terraforming Protocol..."
Sound.Volume = 0.3
wait(1)
TextLabel.Text = "Done!"
Sound.Volume = 0.5
Interactables:FindFirstChild("OxygenEffectPart").ParticleEmitter.Enabled = true
Button.Color = Color3.fromRGB(131, 255, 103)
wait(1)
TextLabel.Text = "Status: Active"
for i, Planet1 in pairs(workspace.Assets.Worlds:GetChildren()) do
if Terraformer:GetAttribute("Planet") then
if Planet1.Name == Terraformer:GetAttribute("Planet") then
local water = Planet1:FindFirstChild("Model"):FindFirstChild("Water")
local surface = Planet1:FindFirstChild("Model"):FindFirstChild("Surface")
if PreviousPlanet == Planet1.Name then
TerraformersOnPlanet += 10 -- i make this amount bigger so that change duration will subtract more from 1 terraformer
end
PreviousPlanet = Planet1.Name
Planet1:SetAttribute("ColorChangeDuration", Planet1:GetAttribute("ColorChangeDuration") - TerraformersOnPlanet)
TweenService:Create(surface, TweenInfo.new(Planet1:GetAttribute("ColorChangeDuration")), {Color = Planet1:GetAttribute("TerraformedColor")}):Play()
if water then
while wait(1) do
if water.Size.Y <= Planet1:GetAttribute("WaterSize").Y then
water.Size += Vector3.new(0.1, 0.1, 0.1)
else
break
end
end
end
end
end
end
end
end)
end
end
end
end
end
end
CelestialTerraformers.ChildAdded:Connect(ChildAdded)