Hi guys!
So I wrote this small script that basically adds a GUI ontop of someone's head when an admin chats a certain command. In this case that would be "wanted/(USERNAME)".
The script works perfectly fine, when typed, the user gets a GUI ontop of their head. My only problem is; the username MUST be typed with correct capitals. Example;
user = Player1
"wanted/Player1" <-- Works
"wanted/player1" <-- Does not work!
How can I make sure the script works even with lowercases, whilst still using the string.sub?
My function:
if string.sub(msg, 1,7) == "wanted/" and game.Players:FindFirstChild(string.sub(msg, 8)) then local guiclone = gui:Clone() guiclone.Parent = game.Players:FindFirstChild(string.sub(msg,8)).Character.Head guiclone.Enabled = true print(string.sub(msg, 8).." is wanted!") end
I would write a separate function which would loop through the players, putting their names in lowercase and putting the sub in lowercase.
Like this:
function GetPlayer(input) local inputLower = string.lower(input) for i,v in pairs(game.Players:GetChildren()) do local lowerName = string.lower(v.Name) if lowerName == inputLower then return v end end return nil end
To use it in your code, you would use this:
if string.sub(msg, 1,7) == "wanted/" then local player = GetPlayer(string.sub(msg, 8)) if player then local guiclone = gui:Clone() guiclone.Parent = player.Character.Head guiclone.Enabled = true print(player.Name .." is wanted!") end end