Is there an easier way to write this, without writing many times if I add more? The models are from replicated storage
textBox:GetPropertyChangedSignal("Text"):Connect(function() if textBox.Text == "DropperOne" then placementModule:new("Dropper1", game.ReplicatedStorage.Models, plot.Plot, plot.PlacedObjects, false, true) textBox.Text = "" textBox.FocusLost = true elseif textBox.Text == "DropperTwo" then placementModule:new("Dropper2", game.ReplicatedStorage.Models, plot.Plot, plot.PlacedObjects, false, true) textBox.Text = "" textBox.FocusLost = true elseif textBox.Text == "DropperThree" then placementModule:new("Dropper3", game.ReplicatedStorage.Models, plot.Plot, plot.PlacedObjects, false, true) textBox.Text = "" textBox.FocusLost = true elseif textBox.Text == "Conveyor" then placementModule:new("Conveyor", game.ReplicatedStorage.Models, plot.Plot, plot.PlacedObjects, false, true) textBox.Text = "" textBox.FocusLost = true end end)
Thanks for the Help!
There actually would be a way to shrink this using, as you might have guessed, dictionaries.
local texts = { DropperOne = "DropperOne", DropperTwo = "DropperTwo", DropperThree = "DropperThree", Conveyor = "Conveyor", } textBox:GetPropertyChangedSignal("Text"):Connect(function() if texts[textBox.Text] then -- check if it exists in our dictionary local val = texts[textBox.Text]; -- now that it exists, lets assign it's value to a variable placementModule:new((val), game.ReplicatedStorage.Models, plot.Plot, plot.PlacedObjects, false, true) -- use the ModuleScript with the value we got textBox.Text = "" textBox.FocusLost = true end end)