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
You can use the string.match
function, or the string.find
function to determine if your string contains the specified substring.
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