Chat Wave Animation Help

This script used to work as intended but I quickly found out that if you type “meh” in the chat the Wave Animation plays, and that’s clearly not in the table.

So how would I detect if a string in the table is in a message, and it doesn’t have to spelled correctly either ( using :lower() )

For example “hI”, “hello how are you”, and “hEy how are you?!” would all play the animation.

LocalScript:

local LocalPlayer = game.Players.LocalPlayer
local WaveMessages = {
	"hi",
	"hello",
	"hey"
}

LocalPlayer.Chatted:Connect(function(ChattedMessage)
	local foundMessage = false
	local Character = LocalPlayer.Character
	local Humanoid = Character:FindFirstChild("Humanoid")
	local WaveAnimationsFolder = game.ReplicatedStorage.Animations.WaveAnimations
	local R15Wave = Humanoid:LoadAnimation(WaveAnimationsFolder.R15)
	local R6Wave = Humanoid:LoadAnimation(WaveAnimationsFolder.R6)
	R15Wave.Looped = false
	R6Wave.Looped = false

	local Message = string.lower(ChattedMessage)

	for _ , v in pairs(WaveMessages) do
		if string.match(Message , v) then
			foundMessage = true
		end
	end
	
	if foundMessage and Character and Humanoid then
		if Humanoid.RigType == Enum.HumanoidRigType.R15 then
			R15Wave:Play()
		elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
			R6Wave:Play()
		end
	end
end)
1 Like
local Game = game
local Players = Game:GetService("Players")

local Phrases = {"Hello", "World", "Roblox", "Lua"}

local function OnPlayerAdded(Player)
	local function OnChatted(Message)
		Message = string.lower(Message) --Uncapitalise the chatted message.
		local State = false --State variable.
		for _, Phrase in ipairs(Phrases) do --Iterate over the array of phrases.
			if string.match(Message, string.lower(Phrase)) then --Check if the phrase is contained within the message.
				State = true --Switch state variables.
				break --Break loop.
			end
		end
		
		if State then
			--Do code.
		else
			--Do other code.
		end
	end
	
	Player.Chatted:Connect(OnChatted)
end

Players.PlayerAdded:Connect(OnPlayerAdded)

For some reason this is not working. I have been trying to fix it by removing the functions OnPlayerAdded and OnChatted, and using something like this,

game.Players.PlayerAdded:Connect(function(Player)
     Player.Chatted:Connect(function(Message)
          --do stuff
     end)
end)

but that does not seem to be working also. Not sure why! :frowning:

1 Like

I’d suggest you do something like this:

for _,v in ipairs(WaveMessages) do
   if Message == v or Message == string.lower(v) then
       -- do something
   end
end

It does not run multiple times or cause any bugs.

1 Like

That’s bot really what I want to use though.

What i’m looking for is things like if you say “heLLO” “hi how are you?” “HEY” the animation would play.

1 Like
for _,v in ipairs(WaveMessages) do
   if string.lower(Message):match(string.lower(v)) then
       -- do something
   end
end

Something like this? I’m pretty sure thats how, If not, There are threads on how to make strings case sensitive.

1 Like

Alrighty, I just tested this, It works well, If it does not work for you, It is most likely something inside of your code.

1 Like

My script seems to not be printing. This is a LocalScript inside of StarterPlayerScripts.

local words = {"hi", "hello", "hey"}

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		for _, NewMessage in ipairs(words) do
			if string.lower(Message):match(string.lower(NewMessage)) then
				--if Character and Humanoid then
					print("dfgdfghega")
				--end
			end
		end
	end)
end)
local OnMessageDoneFiltering = game.ReplicatedStorage:WaitForChild("DefaultChatSystemChatEvents"):WaitForChild("OnMessageDoneFiltering");

OnMessageDoneFiltering.OnClientEvent:Connect(function(Table)
    local Message = Table.Message
    for _, NewMessage in ipairs(words) do
	if string.lower(Message):match(string.lower(NewMessage)) then
		--if Character and Humanoid then
			print("dfgdfghega")
		--end
		end
	end
end)

Let me know if this works…

Use this

local LocalPlayer = game.Players.LocalPlayer
local WaveMessages = {
	"hi",
	"hello",
	"hey"
}

for _ , v in pairs(game.Players:GetPlayers()) do
	v.Chatted:Connect(function(ChattedMessage)
		if v ~= LocalPlayer then return end
		local foundMessage = false
		local Character = LocalPlayer.Character
		local Humanoid = Character:FindFirstChild("Humanoid")
		local WaveAnimationsFolder = game.ReplicatedStorage.Animations.WaveAnimations
		local R15Wave = Humanoid:LoadAnimation(WaveAnimationsFolder.R15)
		local R6Wave = Humanoid:LoadAnimation(WaveAnimationsFolder.R6)
		R15Wave.Looped = false
		R6Wave.Looped = false

		local Message = string.lower(ChattedMessage)

		for _ , v in pairs(WaveMessages) do
			if string.find(Message , v) then
				foundMessage = true
			end
		end
	
		if foundMessage and Character and Humanoid then
			if Humanoid.RigType == Enum.HumanoidRigType.R15 then
				R15Wave:Play()
			elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
				R6Wave:Play()
			end
		end
	end)
end

When I type “h”, it prints once, when I type “hello” it prints 4 times. That isn’t what I wanted, what I was trying to achieve was if you say “hello how are you?”, “hi”, “HI”, “heY”, etc. It would print something once for every message you send.

This also seems to be behaving the same way as this is.

Here’s a video of what’s going on.

(Didn’t know I was recording for a second)

https://gyazo.com/3505ac263c4c7945e138ae0f6f5afc3f

i edited my code, try it again

1 Like

It seems to almost be working! But using the strings in the table in a message doesn’t seem to work. For exameple “hey how are you”, “hi whats up”, “hello :D” would also play the animation. Not just “hI”, “hey”, etc.

Hopefully that makes sense! Thank you so much. :smiley:

Video:
https://gyazo.com/e85c5bd11a2b81eb46afa2fe19f5e8cf

ooooh right forgot about that part lol

its done now, ik the mistake i made, forgot about full sentences

It’s working with full sentences now but now works if you say “h”, “e”, “o”, and etc. I’m so confusedd :frowning:

1 Like

ill just remake the checking part then.

1 Like

here it is

local LocalPlayer = game.Players.LocalPlayer
local WaveMessages = {
	"hi",
	"hello",
	"hey"
}

function check(text)
	if table.find(WaveMessages , text) then return true end
	local words = text:split(" ")

	for _ , v in pairs(words) do
		if table.find(WaveMessages , v ) then
			return true
		end
	end
	return false
end

for _ , v in pairs(game.Players:GetPlayers()) do
	v.Chatted:Connect(function(ChattedMessage)
		if v ~= LocalPlayer then return end
		local Character = LocalPlayer.Character
		local Humanoid = Character:FindFirstChild("Humanoid")
		local WaveAnimationsFolder = game.ReplicatedStorage.Animations.WaveAnimations
		local R15Wave = Humanoid:LoadAnimation(WaveAnimationsFolder.R15)
		local R6Wave = Humanoid:LoadAnimation(WaveAnimationsFolder.R6)
		R15Wave.Looped = false
		R6Wave.Looped = false

		local Message = string.lower(ChattedMessage)

		local foundMessage = check(Message)

		if foundMessage and Character and Humanoid then
			if Humanoid.RigType == Enum.HumanoidRigType.R15 then
				R15Wave:Play()
			elseif Humanoid.RigType == Enum.HumanoidRigType.R6 then
				R6Wave:Play()
			end
		end
	end)
end
1 Like

you’ve been so kind for helping me but now full sentences aren’t working anymore :sob: :sob:

1 Like