Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

String.sub doesn't work on lowercase?

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

1 comment

0

You'd have to create a separate function that retrieves the player.

1 answer

✓ Accepted answer

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

3 comments

0

STOP STEALINGZ MAI ANZERZ!

0

Worked like a charm, thanks!

0

Thee instead of commenting just answer then.

This discussion is preserved as it was. New answers, comments, and votes are closed.