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

How can I get my script to play the sound for all messages including the word help?

In my game, I wanted is so that when players say something in a message a sound would play. I have a script that will play a sound when they say something, but only if it is that specific something and nothing else. if players say "help" then the sound will play, but if they say "can someone help me?" nothing will happen... How would I get the script to play the sound for all messages including the word help? Here is the script:

function onPlayerEntered(newPlayer)
	newPlayer.Chatted:connect(tutorialChatted)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

function tutorialChatted(msg)
	if (msg=="help") then
		local mm = workspace:findFirstChild("Help Sound")
			mm.Playing = true
				
	end
end

2 comments

0

Just remove line 8 and 12

0

but I only want the sound to activate when players say something with help in it, just not restricted to only saying help

1 answer

✓ Accepted answer

You can use the string.match function, or the string.find function to determine if your string contains the specified substring.

######note: define constant values outside of your events! this way, it will only be defined once rather than everytime the event is called.

local mm = workspace:FindFirstChild("Help Sound") --Define outside event

function onPlayerEntered(newPlayer)
	newPlayer.Chatted:connect(tutorialChatted)
end

game.Players.PlayerAdded:connect(onPlayerEntered)

function tutorialChatted(msg)
	if msg:match("help") then --'match' function
		mm:Play()
	end
end

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