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

Why does the "." prefix for a string not work?

Here is a little sample of my code.

boi.Chatted:connect(function(m)
if string.byte(m, ".creators") then
print"w"
end)
end

If you chat ".creators" then it'll print. But for some reason, if you type "!creators" or ";creators" it also prints to the console.

If I change the "." to anything else like ":", it works completely fine. I'm not sure why this is happening, and how can I stop this? (I've already tried tostring.)

4 comments

0

. is used in string patterns; it means "any character". https://developer.roblox.com/articles/string-patterns-reference

0

Is there any way to avoid this? I really want to use this prefix.

0

You could escape it. https://www.lua.org/pil/2.4.html In this case, '.creator'

0

Thanks for posting that link. I'm using "%." instead of "." now.

1 answer

✓ Accepted answer

This is because of string.find's function definition:

number, number string.find(string s, string pattern, number init = 1, number plain = false)

As you can see, the second argument you give it is a pattern. If you take a look at the String Patterns Reference page on the Roblox Developer Hub, you'll see that . is a pattern that matches any character.

To fix this, you must specify before the . in your string pattern that you are explicitly looking for the . character and not just any character. The % character is useful for this.

Client.Chatted:Connect(function(Message)
	if string.find(Message, "%.creators") then
		print("worked!")
	end
end)

1 comment

0

Thanks man!

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