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

Help with knowing how to work with msg:lower() in a chat script?

I have my chat script which works GOOD. But what I am wanting is when someone says 'fireddusk' (which is my roblox username) by itself OR in a sentence, I want this code to run. I have no idea how to do this.

if msg:lower() == 'fireddusk' then
		local Label = Instance.new('TextLabel')
		Label.BackgroundTransparency = 1
		Label.TextStrokeTransparency = 0.8
		Label.TextXAlignment = 'Left'
		Label.TextColor3 = Color3.new(255/255, 170/255, 0/255)
		Label.Font = 'SourceSansBold'
		Label.Size = UDim2.new(1,0,0,15)
		Label.Position = UDim2.new(0,0,1,-15)
		Label.TextScaled = true
		Label.Text = "[SERVER]: Don't say the creators name or you could eat a pickle."
		PushMsgs(Label.Size.Y.Offset)
		Chats[#Chats +1] = Label
		Label.Parent = Container
	end

3 comments

0

You have so much reputation, you've been on this site for quite a while, but you still don't know how to do something as simple as this?

0

My rep is mostly from asking questions. I am a slow learner.

0

Sorry. Didn't mean to be mean.

1 answer

✓ Accepted answer

The easiest way to accomplish this is using string patterns. Using the match function, you could simply ask msg:match("fireddusk") and it would return 'fireddusk' if it exists in the string or nil otherwise.

if msg:lower():match("fireddusk") then
	-- do stuff
end

Edit

Thanks to BlueTaslem for pointing out the error with whitespace. Turns out to be a more complicated problem than I assumed. Should have tested it before I posted.

5 comments

0

If you're just checking if some text is found within a string, I find that :find() is an easier-to-read alternative to "match"

1

Also, %s* is not quite right since it would reject 1) "hi firedusk" (no space after) 2) "firedusk hi" (no space before) 3) "firedusk, hi" (punctuation after), etc

0

True, thanks for pointing that out

0

So what should I do?

0

The code that is posted now will work if "fireddusk" is somwhere in the string msg

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