I have been trying to find a way to find the player through putting their username in a textbox and when I click a button, it will either show that the game found the user or that it didn’t. I have trying to do this through a LocalScript. (I’m not trying to find the player clicking the button, but a way to find anyone who is in the game through searching for their username.)
I’ve been using table.create
and table.find
with no luck. Any help would be grealy appreciated!
This is the script I’ve been using:
local Players = game:GetService("Players")
local button = script.Parent.TextButton
local box = script.Parent.TextBox
local function getPlayer()
local PlayerList = table.create(1, Players:GetChildren())
local PlayerNameInput = box.Text
local PlayerName = game.Players:FindFirstChild(PlayerNameInput)
if table.find(PlayerList, PlayerName, 1) then
print("Found " .. PlayerName .. "!")
else
warn("Could not find that player!")
end
end
button.MouseButton1Click:Connect(function()
if box.Text == " " then
button.Text = "Please input a username!"
wait(1)
button.Text = "Button"
else
getPlayer()
end
end)