I have this script where it will autofill the textbox with the username if I look at part of the username in-game. Heres the problem tho,
It won’t give any errors or output in the output
It won’t put the username in the textbox.
I tried looking for a fix but I can’t find anything!
Heres the script!:
function findUser()
local players = game.Players:GetPlayers()
local text = script.Parent.Text
local matches = {}
for i, Player in ipairs(players) do
local name = Player.Name
local term = string.sub(name, 1, string.len(text))
local match = string.find(term, text)
if match then
table.insert(matches, name)
end
end
-- If we don’t have multiple matches , do stuff
if not #matches > 1 then
script.Parent.Text = matches[1]
end
You don’t seem to be running your findUser() function?
Just wanted to mention on top of this:
If you only use the first match, you can put a break after your table.insert, meaning that code that doesn’t need to run, won’t run.
E.g.
if match then
table.insert(matches, name)
break -- the loop won't look for further records (this time only).
-- you can learn more about 'break' on a lua manual.
end
function findUser()
local players = game.Players:GetPlayers()
local text = script.Parent.Text
local matches = {}
for i, Player in ipairs(players) do
local name = Player.Name
local term = string.sub(name, 1, string.len(text))
local match = string.find(term, text)
if match then
table.insert(matches, name)
script.Parent.Text = matches
break – the loop won’t look for further records (this time only).
– you can learn more about ‘break’ on a lua manual.
end
end
-- If we don’t have multiple matches , do stuff
if not #matches > 1 then
script.Parent.Text = matches[1]
end
When I’m ever in doubt of a new chunk of code or it doesn’t seem to work I just casually throw a few print()'s in there after key parts(if statements and such) and check the output to see what has run. That could help you see where you are at. Good luck!
As @coexperience mentioned above, have you called the function findUser() ? (It does not show in the post.) It may even be something simple. Example from experience: I might think something is wrong with my code and after a few minutes of searching for the bug I find that I disabled my script… Has happened a time or two.