I’m working on a name autofill for my game chat. In it, you can begin typing a player’s name and then hit tab to automatically finish typing the name.
How would you go about reading from what the local player currently has typed in their chatbar? And how do I write to the chatbar to perform the autofill?
Hello there, to know what a player has typed into the chat, you could access player gui from a local script.
This will work if you are using default roblox chat in game.
local playergui=game.Players.LocalPlayer:WaitForChild("PlayerGui")
local ChatGui = playergui:WaitForChild("Chat")
local ChatBarText=ChatGui.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar
local message=ChatBarText.Text
Now, to complete a players name by clicking tab, you could do:
local function findPlayer(name)
for _, player in pairs(game.Players:GetPlayers()) do
if (player.Name:lower():find(name) == 1) then
return player
end
end
end
local uis=game:GetService("UserInputService")
uis.InputEnded:Connect(function(input)
if ChatBarText.Text ~="" and input.KeyCode == Enum.KeyCode.Tab then
local message=ChatBarText.Text:lower()
local plrName=message:split("")
local target_player= findPlayer(plrName)
if target_player ~= nil then
ChatBarText.Text=target_player.Name
end
end
end)
Edit: I just realised that Tab key also creates a " " (space), thats why it wouldn’t work. I just fixed it, so it should work now.