✓ Accepted answer
This is a script that looks for keywords in phrases. If your phrase has ALL of the keywords in it,
for exampleJarvis + Armour or even Jarvis + heal,
it will run the function for the corresponding phrases. The functions for each phrase are inside the table phrases
This should be pretty straightforward but pls let me know if you have any questions - my code can be confusing
match = nil
phrases = {
["Amour"] = {
words = {"Jarvis" , "Armour"},
func = function( p )
print(p.Name .. " activated armor function")
end
},
["Health"] = {
words = {"Jarvis","Heal"},
func = function( p )
print(p.Name .. " activated health function")
end
}
}
function onChatted(msg, recipient, speaker)
print("chatted")
local source = speaker
msg = string.lower(msg)
match = nil
for i,v in pairs(phrases) do
if match~=nil then break end
print("no match, scanning")
local allFound = true
for u,c in pairs(v.words) do
if not msg:match(string.lower(c)) then
allFound = false
end
end
if allFound and match == nil then
match = v
print("match = " .. tostring(v))
end
end
if match then
print("match found, running function")
match.func(source)
match = nil
end
end
function onPlayerEntered(newPlayer)
newPlayer.Chatted:connect(function(msg, recipient) onChatted(msg, recipient, newPlayer) end)
end
game.Players.ChildAdded:connect(onPlayerEntered)
1 comment
That works perfectly! Exactly what I needed. I can learn a lot from this.