I am working on an autofill gui for when you type into a textbox it shows a suggestion. This isnt an error, but everytime I type random upper and lowercase letters, it always sticks to just lowercase instead of how you typed it. My code works perfectly fine, however I'd like to fix this bug.
CLIP: https://medal.tv/clips/56252105/d1337cQiLrCC
TextBox = script.Parent.TextBox
Suggestions = script.Parent.Suggestion
UIS = game:GetService("UserInputService")
function Suggestion(n)
local names = {}
for _,plr in pairs(game.Players:GetPlayers()) do
n = n:lower()
local tn = (plr.Name):lower():sub(1,#n)
if(tn == n) then
table.insert(names,plr.Name)
end
end
if #names == 1 then
return names[1]
else
return nil
end
end
TextBox:GetPropertyChangedSignal("Text"):Connect(function()
if string.len(TextBox.Text) >= 1 then
local plr = Suggestion(TextBox.Text)
if(plr) then
if string.upper(TextBox.Text) == TextBox.Text then
local NameUpper = string.upper(plr)
Suggestions.Text = NameUpper
elseif string.lower(TextBox.Text) == TextBox.Text then
local NameLower = string.lower(plr)
Suggestions.Text = NameLower
else
Suggestions.Text = plr
end
elseif plr == nil then
Suggestions.Text = ("")
end
else
Suggestions.Text = ("")
end
end)
UIS.InputBegan:connect(function(i,gps)
if not gps then return end
if i.KeyCode == Enum.KeyCode.Return then
local plr = Suggestion(TextBox.Text)
if (plr) then
TextBox.Text = plr
print("Successfully autofilled.")
end
end
end)
