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

How to detect if somebody used a letter or not?

Is it possible to detect if the first 'letter' somebody said was a letter or something else like a 9 or a :?

1 answer

✓ Accepted answer

Yes, you can use the string.sub function to slice strings in order to compare parts of them.

msg = ":m hello"

if msg:sub(1, 1) == ":" then
	print(msg:sub(2))
	--^ prints "m hello"
end

Edit: Checking if a string is a letter

function is_letter(s)
	if not s:match("[^%a]") then
		return true
	end
end

print(is_letter(msg:sub(1, 1)) and "It's a letter" or "Not a  letter!")
--> Not a letter!

print(is_letter("a") and "It's a letter!" or "Not a letter!")
--> It's a letter!

4 comments

0

But how do you detect if its any letter at all and without using 26 lines?

0

print(msg:sub(1, 1)) --> :

0

But how do I do it without doing if msg:sub(1,1)=="LETTER" then 26 times to make sure its a letter?

0

I've updated the answer

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