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

How do I make the commands work even when the players name are in lowercase?

Asked by 2 years ago

Currently, I have been trying to make an admin commands system, it works fine but the problem is if I write the players name in lowercase, it never works, is there any way for me to make it so even when the players name is written in lowercase it works?

local headadmins = {''}
local admins = {''}
local lowadmins = {''}
local prefix = "!"

game.Players.PlayerAdded:Connect(function(plr)
    plr.Chatted:Connect(function(eeelol, recipent)
        local message = string.lower(eeelol)
        local splitmessage = message:split(" ")
        local command = splitmessage[1]
        local maincommand = command:split(prefix)

        local commandname = maincommand[2]

        local playername = eeelol:split(" ")[2]


        --Kick Start
        if commandname == "kick" then
            print('they said kick')
            if splitmessage[2] then
                for i, v in pairs(admins) do
                    wait()
                    if plr.Name == v then
                        print('plr is admin')

                        if game.Players:WaitForChild(playername) then
                            local reasonofkick = eeelol:split(playername)
                            print("player exists")
                            game.Players:FindFirstChild(playername):Kick(reasonofkick[2])
                            print('kicked')
                        end

                    end
                end
            end
        end
        --Kick End

        --Teleport Start
        if commandname == "teleport" then
            if splitmessage[2] then
                if splitmessage[3] then
                    for i, v in pairs(lowadmins) do
                        wait()
                        if plr.Name == v then
                            if game.Players:WaitForChild(playername) then
                                local tpcommandidkfirst = eeelol:split(" ")
                                game.Workspace:WaitForChild(tpcommandidkfirst[2]):FindFirstChild("HumanoidRootPart").Position = game.Workspace:WaitForChild(tpcommandidkfirst[3]):FindFirstChild("HumanoidRootPart").Position

                            end
                        end
                    end
                end
            end
        end

        --Teleport End


    end)
end)

1 answer

Log in to vote
0
Answered by
Nep_Ryker 131
2 years ago

You can use the string.lower() method in order to convert any and all uppercase letter of the player's username to lowercase, you can use this to achieve what you have asked.

I'm not sure if this is the best way to do it but I would get a list of all players in the game, then do a for loop with an if statement inside of it.

To give an example:

local PLAYER_NAME = "Nep_Ryker" -- The player you want to kick

for i, v in pairs(game.Players:GetChildren()) do
    if string.lower(v.Name) == string.lower(PLAYER_NAME) then -- If the lowered case version of v.Name equals to the lowered case version of the player name, then kick
        v:kick()
    else
        print("Player not found!")
    end
end

I hope this helped you somewhat.

0
thanks it helped InspireWithFun 9 — 2y
0
Use :GetPlayers instead of :GetChildren() because it checks if the child is a PlayerObject MarkedTomato 810 — 2y
Ad

Answer this question