I’m trying to create an admin command system. It’s functional, but I haven’t coded the piece which allows my scripts to find players based on small snippets of their chat.
If you don’t know what I mean, imagine I said:
;tp zesty (some other player)
What would I do to tell my script to associate “zesty” with “1ZestyChesty1”? Would I just use a for loop on all players’ names and check character by character which name matches the best with “zesty”? That seems so inefficient, but maybe I’m wrong.
Cool question, you will need to have a pretty decent understanding of String Manipulation, especially the “lower” or “upper” and the “sub” and “split” functions. You will also need the Player Instance more specifically the Chatted event, you will furthermore have to deal with arrays which are part of Tables and finally, you will need a Loop (preferably a for loop). I recomend reading the entirety of the 4 articles to get a general understanding of how to excecute your idea. If you need any help, please come back to this thread and please make an effort.
There is a neat function I typed up to help you with this problem.
local Players = game:GetService("Players");
local FindPlayer = function(Str)
for I, V in pairs(Players:GetPlayers()) do
if Str:lower() == (V["Name"]:lower()):sub(1, #Str) then
return V
end
end
end
You can also do this with display names! Simply just have it check for the display name instead.
This will only work when matching the substring after the first char. It’s not going to be very effective when trying to get “dukzae” from “dukzae”, you’d have to say “ukzae”. It’s not going to autocomplete either, you can’t say “ukz” to get “dukzae”
Didn’t sound arrogant to me, I’m pretty sure he was just here to help. Not nice to call people arrogant when they were just trying to help
He obviously was; if I have a functional admin system, I should have a basic understanding of string manipulation, which I do. My question wasn’t asking to be spoonfed, I provided a theory that I would have to index names player-by-player, and said why I was asking for an alternative (I thought it was inefficient.) there was nothing inherently stupid about my question.
Now, you could argue that if I have a basic idea of string manipulation, I could have figured this out on my own. Even if that’s true, at the same time, we all have days where even if we’re experienced at scripting, we fail to see an answer that’s so simple and right in front of us. It’s a human thing. This guy by telling me to “read 4 articles” as a magic solution to my question is arrogant, because he assumes if that’s how it is for him, that’s how it is for me. Nope, I read the articles. I still asked this question anyway.
You mentioned you did not code the lines to handle abreviated names, I provided you with articles for the rest since you mentioned having coded the rest of the script. I was not being arrogant, rather trying to be as informal as possible being it was 4 am and getting on was not an option id take, your question was good though.