Chat Wave Animations Help

As of right now, when you say “hi” the animation plays. But when you say anything else but what’s in the table, for example “Hello, how are you?”, the animation does not play. How do I fix this?

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

LocalPlayer.Chatted:Connect(function(ChattedMessage)
	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)
	if table.find(WaveMessages, Message) 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)

Try this

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