Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Finding a player through a TextBox?

Asked by 3 years ago

I tried making a script that finds a player through a textbox, but it won't work. Any help?

script.Parent.MouseButton1Down:Connect(function()
    local target = script.Parent.Parent.NewTeamPlayerBox.Text

    for _, player in pairs(game:GetService("Players"):GetPlayers()) do
        if player.Name:lower() == target:lower() then
            print("hi")
       end
    end
end)

1 answer

Log in to vote
1
Answered by 3 years ago

easy.

script.Parent.MouseButton1Click:Connect(function() --function the click event, when someone clicks the button.
    local Target = script.Parent.Parent.NewTeamPlayerBox.Text --variable "Target" will be used to indicate the text in the textbox.
    for Index, Player in pairs(game.Players:GetChildren()) do --"Player" will be used to indicate the children of game.Players
        if Player.Name:lower() == Target:lower() then --when they lower the text, it will check if the text matches the players name.
            print("hi") --print hi if it matches the players name.
        end
    end
end)

instead of having to use

game:GetService("Players")

you can just use

game.Players

since Players is already listed in the explorer.

Ad

Answer this question