If you don't understand what the script is suppose to do, just read the information below
When you click button while you have a part of the username, it will print the full username and happy
if you don't type in a username or a part of it it will print sad
the script doesnt work when dont type in the username, please help me
script.Parent.BackGround1.Enter.MouseButton1Click:connect( function() for i,v in next, game.Players:GetChildren() do if string.len(v.Name) >= string.len(script.Parent.BackGround1.UsernameHandler.Text) then if string.lower(script.Parent.BackGround1.UsernameHandler.Text) == string.lower(string.sub(v.Name,0,string.len(script.Parent.BackGround1.UsernameHandler.Text))) then print(v.Name) if script.Parent.BackGround1.UsernameHandler.Text == (v.Name) then print("happy") else print("sad") end end end end end)
The problem was that you compared the text input with itself. Also a string's first character is numbered 1 (not 0). This should work for you :P
local function getPlayer(String) for i, Player in pairs(game.Players:GetPlayers()) do if string.sub(string.lower(Player.Name), 1, string.len(String)) == string.lower(String) then print("Found player:", Player.Name) return Player end end end script.Parent.BackGround1.Enter.MouseButton1Click:Connect(function() local Player = getPlayer(script.Parent.BackGround1.UsernameHandler.Text) if Player then print(Player.Name) end end)