So basically I’m making a weapon spawner and I have an Item Name textbox How would I make it so if a player types in “a” all the weapons with A in the names will show up and if the player types like “Taser” then the button taser will appear and nothing else will?
You can use string.sub, or :find()
(these are 2 methods I know of)
1 Like
Let’s say the typed text called is x
.
If x
was a, it would check all the names that start with a
. Meaning, all the name where the first character is a
, and everything that has an “a” (the name of the label has to correspond with the gun’s name) is stored into a temporary table called show
for example
local x = "a" --this is the text for example
local show = {}
for i, v in pairs(all those lables) do
if string.lower(string.sub(v.Name, 1, #x)) == x then
table.insert(show, v)
end
end
If you want a weapon containing the character and not starting with it you can do
local x = "a" --this is the text for example
local show = {}
for i, v in pairs(all those lables) do
if string.match(string.lower(v.Name), x) then
table.insert(show, v)
end
end
And this would work whatever x is
Then you loop through show
, and make only those labels visible, while the others are invisible, and make sure to make them alligned using UIListLayout, check them out
2 Likes