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 3 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?

01local headadmins = {''}
02local admins = {''}
03local lowadmins = {''}
04local prefix = "!"
05 
06game.Players.PlayerAdded:Connect(function(plr)
07    plr.Chatted:Connect(function(eeelol, recipent)
08        local message = string.lower(eeelol)
09        local splitmessage = message:split(" ")
10        local command = splitmessage[1]
11        local maincommand = command:split(prefix)
12 
13        local commandname = maincommand[2]
14 
15        local playername = eeelol:split(" ")[2]
View all 62 lines...

1 answer

Log in to vote
0
Answered by
Nep_Ryker 131
3 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:

1local PLAYER_NAME = "Nep_Ryker" -- The player you want to kick
2 
3for i, v in pairs(game.Players:GetChildren()) do
4    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
5        v:kick()
6    else
7        print("Player not found!")
8    end
9end

I hope this helped you somewhat.

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

Answer this question