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

Trying to find the username of a player when a few letters are add to a textbox not working?

Asked by 4 years ago
Edited 4 years ago

Introduction

Hi I'm Matt, and I'm making my own custom admin panel. I'm having trouble with my account age finder script that finds a possible matching username of a player then sets a textbox text to the players username, then sets a textlabel to the players account age (Days old). There are no errors in the client or server, I don't know what I did wrong.

Code

Here is my code:

function findUser()
    local players = game.Players:GetPlayers()
    local buttontext = script.Parent.Text
    local answertext = script.Parent.Parent.EnteredPlayerAccountAge.Text
    local matches = {}

    for i, Player in ipairs(players) do
        local name = Player.Name
        local term = string.sub(name, 1, string.len(buttontext))

        local match = string.find(term, buttontext)

        if match then
            table.insert(matches, name)
            name.AccountAge = answertext
        end
    end

    if not #matches > 1 then
        buttontext = matches[1]
    end
end

Conclusion

In conclusion, I would like help with this, as I have looked over many dev forum posts, and the developer wiki and found nothing that could help. Any help is appreciated, this is my first time using strings!

Edits:

I might have found the problem, I forgot to connect the function. Still doesn't work, so if you find anything else please answer.

0
what would you put for the text if you were an admin SoftlockedUnderZero 668 — 4y
0
Could you explain more? I'm confused. matiss112233 258 — 4y
0
like is it caps sensitive? SoftlockedUnderZero 668 — 4y
0
it should be the exact username the player has yes matiss112233 258 — 4y
0
I had a similar problem myself, I found a solution after a few days, it needs some explaining so if you still need help I'd rather you connect me in discord, [CLASSIFIED]#9999 Torren_Mr 334 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Alright so there are a few issues here. I'm going to assume this is all in some sort of screenGui only visible to the player. If it's visible to other players, it'll be a bit more complicated so let me know.

Firstly, this must be in a LocalScript. GUIs should generally be dealth with from the client, as it's the client who views them. In a LocalScript, you don't fire functions on player added, because LocalScripts only run at around the same time the player is added.

Instead, you want your function to run only when input has been entered into the TextBox. There's an event that can help us with this: FocusLost. This will make the function fire whenever new text is added and the player confirms. Your code should look roughly like this, in a LocalScript, located in the Gui:

local buttontext = script.Parent
local answertext = script.Parent.Parent.EnteredPlayerAccountAge

function findUser()
    local matches = {}

    for i, Player in ipairs(game.Players:GetPlayers()) do
        local name = Player.Name
        local match = string.find(name, buttontext.Text)

        if match then
            table.insert(matches, name)
            answertext.Text = tostring(Player.AccountAge)
        end
    end

    if not #matches > 1 then
        buttontext.Text = matches[1]
    end
end

script.Parent.FocusLost:Connect(findUser)
0
Still doesn't work, yes I converted it to a LocalScript. No output, still doesn't print. I have a separate script that has PlayersAllowed which are the players that can see the gui. matiss112233 258 — 4y
0
I'll try this tomorrow. I'm not gonna watch Super Bowl 54 admin4lifenow -6 — 4y
0
Try it again, just edited it a bit cowsoncows 951 — 4y
0
So I tried it, the "for i, player in ipairs" prints! It doesnt work though, when i type a name in, the error "Players.matiss112233.PlayerGui.MattsAdminGui.MainFrame.RoundedBorders.CheckPlayerAccountAgeFrame.PlayerUsernameEnterBox.FindPlayersEnteredInBox:10: bad argument #2 to 'find' (string expected, got nil)" matiss112233 258 — 4y
0
That means you didn't write anything in the textBox cowsoncows 951 — 4y
Ad

Answer this question