Im trying to make a textbox where you type in the players name if they are in the game it will print “Player is in game” I cant figure out how to do this but I know I’m close I tried this script using the local players name to see if they’re name is what they type.
local players = game.Players:GetPlayers()
local textBox = script.Parent
textBox.ClearTextOnFocus = true
local function onFoucusedLost(enterPressed, _inputObject)
if enterPressed then
print("Enter Pressed")
local typed = textBox.Text
local isPlayer = table.Find(players, typed)
if typed == game.Players.LocalPlayer.Name then
print("This Player Is In Game")
else
print("This Player Is Not In Game")
end
end
end
textBox.FocusLost:Connect(onFoucusedLost)
I want to see if ANOTHER player is in the game how do I do this thanks for any help
You need to declare your local players inside the function. when you create the variable at the start it is locked-in with what ever players are currently logged in, maybe none. You are close! table.find cannot find by name though so you need to iterate over the players array.
local players = game.Players:GetPlayers()
for _, player in players do
if player.Name == typed or player.DisplayName == typed then
return true
end
end
local Game = game
local Script = script
local Players = Game:GetService("Players")
local TextBox = Script.Parent
local function OnFocusLost(EnterPressed, InputObject)
if not EnterPressed then return end
local Player = Players:FindFirstChild(TextBox.Text)
if Player then print(Player.Name) end
end
TextBox.FocusLost:Connect(OnFocusLost)