I currently have this auto-fill script and it works great and auto-fills but its not working with caps and does this:
Is there anyway to fix this?
Code:
local Players = game:GetService("Players")
local ContextActionService = game:GetService("ContextActionService")
local Gui = script.Parent
local PlayerName = script.Parent
local AutoFill = script.Parent.Parent.Autofill
local function GetPossiblePlayer(String)
if String == "" then return nil end
local PlayerList = Players:GetPlayers()
for _, Player in pairs(PlayerList) do
if Player.Name:sub(1, #String):lower() == String:lower() then
return Player
end
end
return nil
end
local function PlayerNameChanged(Property)
if Property == "Text" then
local PossiblePlayer = GetPossiblePlayer(PlayerName.Text)
if PossiblePlayer then
AutoFill.Visible = true
AutoFill.Text = PossiblePlayer.Name
else
AutoFill.Visible = false
end
end
end
local function OnTabPressed(_, inputState)
if inputState == Enum.UserInputState.Begin then
local PossiblePlayer = GetPossiblePlayer(PlayerName.Text)
if PossiblePlayer then
PlayerName.Text = PossiblePlayer.Name:lower()
end
end
end
PlayerName.Changed:Connect(PlayerNameChanged)
ContextActionService:BindAction("OnTabPressed", OnTabPressed, false, Enum.KeyCode.B)
local function PlayerNameChanged(Property)
if Property == "Text" then
local PossiblePlayer = GetPossiblePlayer(PlayerName.Text)
if PossiblePlayer then
AutoFill.Visible = true
-- put my scrpt here
else
AutoFill.Visible = false
end
end
end
There is one problem tho : idk what you do with PlayerName.Text, but lets say that the name of the player is “Hello” and you type “hello”, if you do something like
Players:FindFirstChild(PlayerName.Text) -- which is equal to "hello"
it will not find the player since the ‘H’ is not upper case
You would have to do
local playerName = GetPossiblePlayer(PlayerName.Text).Name