local UIS = game:GetService("UserInputService")
local autofill = script.Parent.Autofill
local box = script.Parent
box:GetPropertyChangedSignal("Text"):Connect(function()
for i,v in pairs(game.Players:GetChildren()) do
local name = box.Text:split(" ")[#box.Text:split(" ")]
if name ~= "" and name:len() > 2 and string.sub(v.Name,1,name:len()) == name then
autofill.Text = box.Text:gsub(name,v.Name)
UIS.InputBegan:Connect(function(i,gpe)
if i.KeyCode == Enum.KeyCode.Tab then
box.Text = autofill.Text
end
end)
else
autofill.Text = ""
end
end
end)
Make sure to use the search feature before posting a new thread. There are plenty of resources showing you ways to achieve this. Look into the string api to figure out how to separate the other methods (@ and w/). I’d recommend iterations and string.split.
Sorry if there is weird formatting I sent this from my phone. If you need a clearer explanation I can get back to you from my pc with something more personalized.
local UIS = game:GetService("UserInputService")
local autofill = script.Parent.Autofill
local box = script.Parent
local function getPlayer(name)
name = name:gsub('%s+', '') or name
for i, player in pairs(game:GetService('Players'):GetPlayers()) do
if player.Name:lower():match('^'.. name:lower()) then
return player.Name
end
end
return nil
end
local Keyword = " " -- set it to nothing if you want to instantly find it after match
local MinMatchLenght = 3 -- minimum characters before can match
box:GetPropertyChangedSignal("Text"):Connect(function()
local characters = box.Text:split("")
for i,word in pairs(box.Text:split(" ")) do
local txt = getPlayer(word)
if txt and #word > MinMatchLenght and txt ~= word then
local min,max = string.find(box.Text,word)
local before,after = characters[min-1] or " ",characters[max]
if after == Keyword and before == " " then
local Position = max + (#txt - #word)
--box.Text = string.gsub(box.Text,word,txt)
--box.CursorPosition = Position+1
-- not sure where to set the text :P
end
end
end
end)
yea doesnt work did a few tweaking cuz before that it didnt work at all!
local UIS = game:GetService("UserInputService")
local autofill = script.Parent.Autofill
local box = script.Parent
local function getPlayer(name)
name = name:gsub("@","")
name = name:gsub('%s+', '') or name
for i, player in pairs(game:GetService('Players'):GetPlayers()) do
if player.Name:lower():match('^'.. name:lower()) then
return player.Name
end
end
return nil
end
local Keyword = "" -- set it to nothing if you want to instantly find it after match
local MinMatchLenght = 2 -- minimum characters before can match
box:GetPropertyChangedSignal("Text"):Connect(function()
local characters = box.Text:split("")
for i,word in pairs(box.Text:split(" ")) do
local txt = getPlayer(word)
if txt and #word > MinMatchLenght and txt ~= word then
local min,max = string.find(box.Text,word)
local before,after = characters[min-1] or " ",characters[max]
if after == Keyword or before == " " then
local Position = max + (#txt - #word)
autofill.Text = string.gsub(box.Text,word,txt)
--box.CursorPosition = Position+1
-- not sure where to set the text :P
else
autofill.Text = ""
end
end
end
end)