local SteamedMilkMachine = game.Workspace:WaitForChild('SteamedMilkMachine') local EspressoMachine = game.Workspace:WaitForChild('EspressoMachine') SteamedMilkMachine.Touched:connect(function(hit) if hit.Parent.Name == 'Cup' then hit.Parent.Name = 'Steamed Milk' end end) EspressoMachine.Touched:connect(function(hit) if hit.Parent.Name == 'Cup' then hit.Parent.Name = 'Espresso'' end end)
It's a bit confusing to what your doing. But, This looks a bit better:
local count = 0 script.Parent.Touched:Connect(function(hit) local hp = h.Parent count = count + 1 -- Depends What Is Touching It. if h.Parent.Name == 'Cup' then hp.Name = "["..count.."] Steamed-Milk" elseif h.Parent.Name == 'Steamed-Milk' then hp.Name = "["..count.."] Cappuccino" else hp.Name = "["..count.."] Espresso Blend" end end)
I don't think efficiency and neatness are really your problem here, the code just has bugs.
script.Parent.Touched:connect(function(h)--Change 'script.Parent' if h.Parent.Name == 'Cup' then-- This station is Steamed Milk. h.Parent.Name = '[1]Steamed-Milk' elseif h.Parent.Name == 'Cup' then h.Parent.Name = '[2]Steamed Milk' end end) script.Parent.Touched:connect(function(h)--Change 'script.Parent' if h.Parent.Name == 'Steamed-Milk' then-- This station is an Espresso Blend. h.Parent.Name = '[3]Cappuccino' elseif h.Parent.Name == 'Cup' then h.Parent.Name = '[4]Espresso Blend' end end)
The first bug is that your first if-elseif block has both ifs checking the same condition, h.Parent.Name == 'Cup'
, so you'll never end up with a cup named '[2]Steamed Milk' because that's unreachable code.
The next bug is that the other machine looks for a cup named 'Steamed-Milk' with an exact string compare (not accounting for the [1] or [2]), and you never name a cup this. string.find(h.Parent.Name,"Steamed-Milk")
would work... but ...only if you don't use 'Steamed-Milk' in one place and 'Steamed Milk' in the other. Hypens matter (bug 3).
The fourth bug is that you are making a cappuccino by adding espresso to steamed milk, but this is not how you make a cappuccino. You add steamed milk to espresso, the order matters, so you have the wrong machine producing this drink.