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)
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,
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)
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.
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.
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