Hi,
I'm trying to find a method that when I type and submit something in a textbox or chat, the item would spawn in my inventory. However, the problem is that I have like 100 different items I would like to spawn, and even if I change or add something minor, I have to change each line of the script. For example:
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Return then
if theText== "Handle" then
local cloneObj= game.ReplicatedStorage:FindFirstChild("Handle",true):Clone()
cloneObj.Parent= game.StarterGui.Inventory.Itembag
elseif theText== "Med Handle" then
local cloneObj= game.ReplicatedStorage:FindFirstChild("Med Handle",true):Clone()
cloneObj.Parent= game.StarterGui.Inventory.Itembag
elseif theText== "Large Handle" then
local cloneObj= game.ReplicatedStorage:FindFirstChild("Large Handle",true):Clone()
cloneObj.Parent= game.StarterGui.Inventory.Itembag
elseif theText== "Hull" then
local theClonedItem= theText
createItemCloneEvent:FireServer(theClonedItem)
--etc etc etc
end
end
end
My attempt was to rewrite all the items in the beginning, like this:
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.Return then
if
theText== "Handle" or
theText== "Med Handle" or
theText== "Large Handle" or
theText== "Hull"
then
--local theClonedItem= theText
createItemCloneEvent:FireServer(theClonedItem)
end
end
end
What this script basically does is that it will search for an item in the Rep Storage directory; it finds the item regarding what I typed in the text box by name and copies it to my inventory. However, I guess I will have to input every name of those 100 items with my proposed method.
Thanks,
Houlardy

3 comments
I answered your question.
Tried to anyway
if I helped you out please accept my answer. Otherwise comment how I can help you better