Hello!
I just wanted to see if there is any flaws in my factory code. I am trying to improve bad habits.
local main = require(script.Parent:FindFirstChild("FactoryAssets"))
script.Parent.Parent.TotalAssets.Changed:Connect(function()
for i, v in pairs(script.Parent.Parent.FactoryPlots:GetChildren()) do
if v:IsA("Model") then
if v.FactoryType.Value == "Bread" then
-----BREAD-----
if v.Factory.Full.Value == false and main.WheatCrops >= 5 then
main.WheatCrops -= 5
v.Factory.Full.Value = true
main.Bread += 1
end
elseif v.FactoryType.Value == "Scythe" then
-----SCYTHE-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 4 then
main.Wood -= 4
v.Factory.Full.Value = true
main.WoodScythe += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Steel >= 1 then
main.Wood -= 3
main.Steal -= 1
v.Factory.Full.Value = true
main.SteelScythe += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Titanium >= 1 then
main.Wood -= 3
main.Titanium -= 1
v.Factory.Full.Value = true
main.TitaniumScythe += 1
end
end
elseif v.FactoryType.Value == "Axe" then
-----AXE-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 4 then
main.Wood -= 4
v.Factory.Full.Value = true
main.WoodAxe += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Steel >= 1 then
main.Wood -= 3
main.Steal -= 1
v.Factory.Full.Value = true
main.SteelAxe += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Titanium >= 1 then
main.Wood -= 3
main.Titanium -= 1
v.Factory.Full.Value = true
main.TitaniumAxe += 1
end
end
elseif v.FactoryType.Value == "Hammer" then
-----HAMMER-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 4 then
main.Wood -= 4
v.Factory.Full.Value = true
main.WoodHammer += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Steel >= 1 then
main.Wood -= 3
main.Steal -= 1
v.Factory.Full.Value = true
main.SteelHammer += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Titanium >= 1 then
main.Wood -= 3
main.Titanium -= 1
v.Factory.Full.Value = true
main.TitaniumHammer += 1
end
end
elseif v.FactoryType.Value == "Sword" then
-----SWORD-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 4 then
main.Wood -= 4
v.Factory.Full.Value = true
main.WoodSword += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Steel >= 1 then
main.Wood -= 3
main.Steal -= 1
v.Factory.Full.Value = true
main.SteelSword += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Titanium >= 1 then
main.Wood -= 3
main.Titanium -= 1
v.Factory.Full.Value = true
main.TitaniumSword += 1
end
end
elseif v.FactoryType.Value == "Fishing" then
-----FISHING-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 4 then
main.Wood -= 4
v.Factory.Full.Value = true
main.WoodFishingPole += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Steel >= 1 then
main.Wood -= 3
main.Steal -= 1
v.Factory.Full.Value = true
main.SteelFishingPole += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Titanium >= 1 then
main.Wood -= 3
main.Titanium -= 1
v.Factory.Full.Value = true
main.TitaniumFishingPole += 1
end
end
elseif v.FactoryType.Value == "Armor" then
-----ARMOR-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 4 then
main.Wood -= 4
v.Factory.Full.Value = true
main.WoodArmor += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Steel >= 1 then
main.Wood -= 3
main.Steal -= 1
v.Factory.Full.Value = true
main.SteelArmor += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Titanium >= 1 then
main.Wood -= 3
main.Titanium -= 1
v.Factory.Full.Value = true
main.TitaniumArmor += 1
end
end
elseif v.FactoryType.Value == "Explosives" then
-----EXPLOSIVES-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Steel == 2 then
main.Wood -= 2
main.Steel -= 2
v.Factory.Full.Value = true
local numb = math.random(1, 3)
if numb == 1 then
main.BasicBomb += 1
elseif numb == 2 then
main.BasicC4 += 1
elseif numb == 3 then
main.BasicRocketLauncher += 1
end
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 1 and main.Steel == 3 then
main.Wood -= 1
main.Steel -= 3
v.Factory.Full.Value = true
local numb = math.random(1, 3)
if numb == 1 then
main.GoodBomb += 1
elseif numb == 2 then
main.GoodC4 += 1
elseif numb == 3 then
main.GoodRocketLauncher += 1
end
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Titanium == 2 then
main.Wood -= 2
main.Titanium -= 2
v.Factory.Full.Value = true
local numb = math.random(1, 3)
if numb == 1 then
main.PowerfulBomb += 1
elseif numb == 2 then
main.PowerfulC4 += 1
elseif numb == 3 then
main.PowerfulRocketLauncher += 1
end
end
end
elseif v.FactoryType.Value == "Gun" then
-----GUN-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Steel >= 2 then
main.Wood -= 2
main.Steel -= 2
v.Factory.Full.Value = true
main.BasicGun += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 1 and main.Steel >= 3 then
main.Wood -= 1
main.Steal -= 3
v.Factory.Full.Value = true
main.GoodGun += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Titanium >= 2 then
main.Wood -= 2
main.Titanium -= 2
v.Factory.Full.Value = true
main.PowerfulGun += 1
end
end
elseif v.FactoryType.Value == "Meat" then
-----MEAT-----
if v.Factory.Full.Value == false and main.FarmingMeat >= 2 then
main.FarmingMeat -= 2
v.Factory.Full.Value = true
main.Meat += 1
end
elseif v.FactoryType.Value == "Mech" then
-----MECH-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Steel >= 2 then
main.Wood -= 2
main.Steel -= 2
v.Factory.Full.Value = true
main.BasicMech += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 1 and main.Steel >= 3 then
main.Wood -= 1
main.Steal -= 3
v.Factory.Full.Value = true
main.GoodMech += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Titanium >= 2 then
main.Wood -= 2
main.Titanium -= 2
v.Factory.Full.Value = true
main.PowerfulMech += 1
end
end
elseif v.FactoryType.Value == "Tank" then
-----MINI TANK-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Steel >= 2 then
main.Wood -= 2
main.Steel -= 2
v.Factory.Full.Value = true
main.BasicTank += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 1 and main.Steel >= 3 then
main.Wood -= 1
main.Steal -= 3
v.Factory.Full.Value = true
main.GoodTank += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Titanium >= 2 then
main.Wood -= 2
main.Titanium -= 2
v.Factory.Full.Value = true
main.PowerfulTank += 1
end
end
elseif v.FactoryType.Value == "Mortar" then
-----MORTAR-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Steel >= 2 then
main.Wood -= 2
main.Steel -= 2
v.Factory.Full.Value = true
main.BasicMortar += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 1 and main.Steel >= 3 then
main.Wood -= 1
main.Steal -= 3
v.Factory.Full.Value = true
main.GoodMortar += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Titanium >= 2 then
main.Wood -= 2
main.Titanium -= 2
v.Factory.Full.Value = true
main.PowerfulMortar += 1
end
end
elseif v.FactoryType.Value == "Rice" then
-----RICE-----
if v.Factory.Full.Value == false and main.RiceCrops >= 5 then
main.RiceCrops -= 5
v.Factory.Full.Value = true
main.Rice += 1
end
elseif v.FactoryType.Value == "Rifle" then
-----RIFLE-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Steel >= 2 then
main.Wood -= 2
main.Steel -= 2
v.Factory.Full.Value = true
main.BasicRifle += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 1 and main.Steel >= 3 then
main.Wood -= 1
main.Steal -= 3
v.Factory.Full.Value = true
main.GoodRifle += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Titanium >= 2 then
main.Wood -= 2
main.Titanium -= 2
v.Factory.Full.Value = true
main.PowerfulRifle += 1
end
end
elseif v.FactoryType.Value == "Robot" then
-----ROBOT-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 1 and main.Steel >= 3 then
main.Wood -= 1
main.Steel -= 3
v.Factory.Full.Value = true
main.BasicRobot += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Steel >= 4 then
main.Steal -= 4
v.Factory.Full.Value = true
main.IntermediateRobot += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Steel >= 2 and main.Titanium >= 2 then
main.Steel -= 2
main.Titanium -= 2
v.Factory.Full.Value = true
main.AdvancedRobot += 1
end
elseif v.FactoryType.Value == "Shield" then
-----SHIELD-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 4 then
main.Wood -= 4
v.Factory.Full.Value = true
main.WoodShield += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Steel >= 1 then
main.Wood -= 3
main.Steal -= 1
v.Factory.Full.Value = true
main.SteelShield += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 3 and main.Titanium >= 1 then
main.Wood -= 3
main.Titanium -= 1
v.Factory.Full.Value = true
main.TitaniumShield += 1
end
end
elseif v.FactoryType.Value == "Turret" then
-----TURRET-----
if v.Factory.FactoryLevel.Value == 1 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Steel >= 2 then
main.Wood -= 2
main.Steel -= 2
v.Factory.Full.Value = true
main.BasicTurret += 1
end
elseif v.Factory.FactoryLevel.Value == 2 then
if v.Factory.Full.Value == false and main.Wood >= 1 and main.Steel >= 3 then
main.Wood -= 1
main.Steal -= 3
v.Factory.Full.Value = true
main.GoodTurret += 1
end
elseif v.Factory.FactoryLevel.Value == 3 then
if v.Factory.Full.Value == false and main.Wood >= 2 and main.Titanium >= 2 then
main.Wood -= 2
main.Titanium -= 2
v.Factory.Full.Value = true
main.PowerfulTurret += 1
end
end
end
end
end
end
end)