if I press G, I want the script to print Grapes = 15 in the output.
Or if I press a letter, I want the scrip to print all the keys and values of all keys starting from that letter.
you can get the key to string by doing Input.KeyCode.Name the loop through the table with a for loop, use string.sub to get the first letter and if it’s the same break so it doesn’t continue looping
local firstValue
for indexName:string, value:number in players do
local FirstLetter = string.sub(indexName,1,1)
if string.upper(FirstLetter) == inputName then
firstValue = indexName
break
end
end
sorry if there’s any errors i wrote this on mobile
Im not good at manipulating strings, but to get a whole filter list, I would try to populate a new filterTable to make it easier at least for me:
local Fruits = {
Apples = 5,
Oranges = 10,
Grapes = 15,
Abanana = 20
}
local FilterTable = {}
for n, v in pairs(Fruits) do
if not FilterTable[string.sub(n, 1, 1)] then
FilterTable[string.sub(n, 1, 1)] = {n}
else
table.insert(FilterTable[string.sub(n, 1, 1)], n)
end
end
-- Print whole Filters
warn(FilterTable)
-- Print Filters which starts with A
print(FilterTable["A"])
-- Find the values of Filters that start with A
for _, f in pairs(FilterTable["A"]) do
warn(f, ":", Fruits[f])
end