Hello DevForum Community!
Today, I'm looking for help, I've struggled with this so it would be appreciated if you could give me ideas for the solution! I'm trying my best to explain this, although, I might be not the best explainer out here.
What I'm trying to achieve is to make a list using tables ( {} ), I've finished the list and the generation but what I'm trying to achieve now is to:
- Each item in the list has its own value.
- But for the item values, the user must type the value into a textbox.
So like, you start with an Item, let's say Item1, I've already set its value in the script (But however in the real code I want to make it so you have to type the value first if there are 0 items in the list then press the Add button for Item1 with its value to appear). Now, in-game, I press the button, Item2 appears however its value is nil, you have to type what value you want for Item2 into the TextBox, you hit the enter in the textbox which inserts a value into Item2 and also erases the Textbox's text. And so on...
The Script
It’s a localscript:
Items = { }
Items[1] = "Item1"
Funcs = {
["Item1"] = function()
print("Apple") -- For example our first String to print is "Apple" in Item1
end;
}
Buttons = { }
List = script.Parent.ScrollingFrame
script.Parent.TextButton.MouseButton1Click:Connect(function()
for i = 1,#Items do
Items[i+1] = "Item"..i+1 -- this adds more buttons by each presses
Item = Instance.new("TextButton", List)
Item.Name = Items[i]
Item.AutoButtonColor = false
Item.Text = " "..Items[i]
Item.TextXAlignment = Enum.TextXAlignment.Left
Item.TextColor3 = Color3.new(255/255, 255/255, 255/255)
Item.Font = Enum.Font.ArialBold
Item.FontSize = Enum.FontSize.Size14
Item.TextScaled = true
Item.TextWrapped = true
Item.TextXAlignment = "Center"
Item.TextYAlignment = "Center"
Item.BackgroundColor3 = Color3.new(113/255, 113/255, 113/255)
Item.BorderColor3 = Color3.new(0, 0, 0)
Item.Size = UDim2.new(0, 108,0, 32)
Item.Position = UDim2.new(0, 0, 0.045*(i-1), 0)
game.Players.LocalPlayer.PlayerGui.ScreenGui.Add.FocusLost:Connect(function()
-- when you type inside the textbox and hit enter:
-- insert a StringValue based on the textbox's text into the Item, each string is something different word. E.g.: Item1 is Apple, Item2 is Pear and so on
end)
if Funcs[Items[i]] then
Item.AutoButtonColor = true
Item.MouseButton1Down:Connect(function()
Funcs[Items[i]]()
end)
end
table.insert(Buttons, Item)
end
end)
How it looks like & works like
(This is actually not how the UI will look like in its final form, it will look entirely different.)
Link for the example video
Anyway, here we are; we reached the bottom of this page. I would like to thank you to whoever reads this post and willing to help.
Ciao!
~ Cronley
I would facepalm so hard if the solution is actually easy