Make FindFirstChild not vase sensitive?

I am working on custom admin for a game and i have a few commands but the player names have to be like XxTESTERxX instead of xx or xxtesterxx and it uses FindFirstChild so it can use use strings from the onChatted but it is case sensitive and annoying. IS there any way around this annoyance? It also teleports to non players that have HumanoidRootParts which i like so i want to keep so i cant look at the player list.
Is there anything i can try to make it not case sensitive.

string:lower() will return the given string as lowercase if this is what you’re asking for. Using this will allow the player to type the player name regardless of capitalization.

I know that but WaitForChild is case sensitive so that really would work if i needed to type AbCdEfGhIjKlMnOp and it got returned in all lowercase so my commands wouldnt work

You need to lower the typed message and their name and match it. If you would post your code I could help you a little more but it is hard to tell you without seeing what you have currently.

All i am using to find the player and see if it exists is a FindFirstChild looking for the player with the name that is the same as the string that was provided. Nothing fancy really

Well I cannot help you until code is posted, I’m not gonna try to guess what your code looks like

			if msg:sub(1, TP:len()):lower() == TP:lower() then
				local otherPlayer = msg:sub(TP:len() + 1) 
				local teleportTarget = game.Workspace:FindFirstChild(otherPlayer):FindFirstChild("HumanoidRootPart")
				p.Character.HumanoidRootPart.CFrame = teleportTarget.CFrame
			end
end

this is one of the commands i am talking about
edit: Oops wrong command!

FindFirstChild is provided as a convenience. If you want to change the behavior, just make your own FindFirstChild that fits your needs

function FindFirstChild(parent, name)
    name = string.lower(name)
    for i,v in pairs(parent:GetChildren()) do
        if string.lower(v.Name) == name then
            return v
        end
    end
end
4 Likes

If you want to find a player by their name without worrying about capitalization, you should change both string’s capitalization so they are the same (either both uppercase or both lowercase)

Which would look something like this:

local str = "XxTESTERxX"
for _,v in pairs(game:GetService("Players"):GetPlayers()) do
    if v.Name:lower() == str:lower() then
        -- code
    end
end

I just said that i cant get the list of players since it also teleports to NPCs which is intended.

The idea would be the same, just using GetChildren instead of GetPlayers.

Insert NPC names into a table and compare that way?

If you want commands to work on both NPCs and Players, it might be a good idea to place them in the same directory so you don’t have to search through the entire workspace for NPCs

Possible solution:

local str = "XxTESTERxX"
-- place the NPCs and player characters in a model called Characters under workspace
for _,v in pairs(workspace.Characters:GetChildren()) do
    if v.Name:lower() == str:lower() then
        -- code
    end
end
1 Like

That makes sense. Thanks for explaining. I may just keep it case sensitive and annoying atm because the game is unorganized because of a BUNCH of different people trying to get the basic features completely functional and stuff like saving the backpack and making the shop system not as basic so keeping the NPCs in the same folder would be hard and indexing thousands or even millions of parts in workspace with p or m in the name would be ridiculous now that i think of it.When the game is more organized i might try adding it.
Thanks for the help

1 Like