Making autofill system

So I am making a autofill system. I don’t know how to explain so ill give a example

input = "kid"
autofill_to = "kidsteve923"
input = "@kid"
autofill_to = "@kidsteve923
input = "hikid"
autofill_to = "hikidsteve923"

get it?
my current one only works like

input = "/w kid"
autofill_to = "/w kidsteve923"
input = "@kid"
autofill_to = nil -- doesnt autofill

script:

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)
1 Like

Player search function

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.

I did used the search function on google but didn’t found any thing!

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)

editing wait

HOL UP ima go test it :slight_smile:

im still editing it , it wont work

oh… didnt understood what u meant by editing wait lol sorry…

ok you can check it out now, i dont know where to update the text so i guess you will figure it out alone

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)