I am trying to make a machine that alloys 3 copper and 1 tin into 1 bronze. The drop collecting does work, but the drop output part doesn't work. Help?
local i1 = script.Parent.Input1 local i2 = script.Parent.Input2 local out = script.Parent.Output local gui = script.Parent.Screen.SurfaceGui material1 = 0 material2 = 0 excess1 = false -- Some values that buttons are going to control excess2 = false alloy = true i1.Touched:connect(function(hit) if hit:FindFirstChild("Cash") then material1 = material1 + 1 gui.Amount1.Text = material1 game.Debris:AddItem(hit,0) end end) i2.Touched:connect(function(hit) if hit:FindFirstChild("Cash") then material2 = material2 + 1 gui.Amount2.Text = material2 game.Debris:AddItem(hit,0) end end) if material1 >= 3 and material2 >=1 and alloy == true then -- PROBLEM POINT wait(script.Parent.AlloySpeed.Value) local part = Instance.new("Part",workspace.PartStorage) part.BrickColor = BrickColor.new("Bronze") part.Material = "Metal" local cash = Instance.new("IntValue",part) cash.Name = "Cash" cash.Value = 6 part.CFrame = out.CFrame part.FormFactor = 3 part.Size = Vector3.new(1.2,1.2,1.2) game.Debris:AddItem(part,20) material1 = material1 - 3 material2 = material2 - 1 gui.Amount1.Text = material1 gui.Amount2.Text = material2 end
Code runs sequentially, and as soon as it can. The if
at the bottom of the script will run as soon as the script begins, and only then.
The simplest solution is to put it in a while
loop that checks constantly:
while wait() do -- do it very often if material1 >= 3 and material2 >=1 and alloy == true then -- PROBLEM POINT wait(script.Parent.AlloySpeed.Value) local part = Instance.new("Part",workspace.PartStorage) part.BrickColor = BrickColor.new("Bronze") part.Material = "Metal" .... -- rest of the stuff end end