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

How would I fix this script to make my pet say a specific phrase when I say a specific phrase?

Ok, so basically, I created a simple script which makes your pet chat when you chat, and it repeats what you say. The one problem is, I put in a couple key phrases, like "I'm dumb" or "I'm an idiot" where it would instead say "You think I don't know that?" instead of repeating the player, to add a bit of humor. The one problem is, when I say those key phrases, it still repeats the player. Why is this?

local chatservice = game:GetService("Chat")
local plrname = script.Parent.Parent.Name
local plr = game.Players:FindFirstChild(plrname)

plr.Chatted:Connect(function(msg)
	if msg == "I'm dumb" or msg == "I'm an idiot" or msg == "I'm stupid" or msg == "I'm an idot" then
		wait(1)
		chatservice:Chat(script.Parent, "You think I don't know that?", "White")
	else
		chatservice:Chat(script.Parent, msg, "White")	
	end
end)

4 comments

0

Are you writing the message properly? Its caps sensitive

0

Yes. I copy and pasted one of the phrases directly from the script.

0

Try printing msg

0

Well, the pet I have repeats what I say. So, printing the message would do the same thing the pet does, just in the output console.

1 answer

✓ Accepted answer

There have been multiple questions for this lately. Basically it comes down to the fact that the input message text contains a newline characters at the end of the string. You need to first trim your string (get rid of trailing whitespaces) before you can compare it.

You can find a code sample of a similar issue here: https://scriptinghelpers.org/questions/111978/issues-encountered-when-trying-to-make-the-game-respond-to-certain-words-in-chat#102790

1 comment

0

Thanks!

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