For example, if the word “cheese” was in filterWords1, and the player says cheese, I want it to print a random word from replaceWords1, vice versa if “orange” and “apple” are in filterWords2 then when the player says apple or orange, it will choose a random word from replaceWords2, not replaceWords1. If you have a better way of doing this that would work too, this is just what I thought of.
Example script:
local filterWords = {
filterWords1 = {"word in here"},
filterWords2 = {"word in here", "word in here"},
filterWords3 = {"word in here", "word in here", "word in here"}
}
local replaceWords = {
replaceWords1 = {"replacement word in here"}, --replacement words for filterWords1
replaceWords2 = {"replacement word in here", "replacement word in here"}, --replacement words for filterWords2
replaceWords3 = {"replacement word in here" "replacement word in here", "replacement word in here"} --replacement words for filterWords3
}
also I want to be able to add more filterWords like filterWords4 and replaceWords4. Let me know if you need some more information
Yeah but I want 2 tables, and when a word is said in the wordTable1 or wordTable2, it will choose a random word from replacementWords1 or replacementWord2 depending on what word they said, look at the example I gave
game.Players.PlayerAdded:Connect(function(plr)
local tab = {
Word1 = {Good = "Alr", Bad = "NO"},
Word2 = {Good = "Good", Bad = "Bad"}
}
plr.Chatted:Connect(function(chat)
for _,v in pairs(tab) do
if chat == v.Good then
print(v.Bad)
elseif chat == v.Bad then
print(v.Good)
end
end
end)
end)
game.Players.PlayerAdded:Connect(function(plr)
local tab = {
Word1 = {Good = "Alr", Bad = "NO"},
Word2 = {Good = {"Apple","Orange"}, Bad = {"Are bad","NO ew..", "Nope."}}
}
plr.Chatted:Connect(function(chat)
for _,v in pairs(tab) do
for i = 1,#v.Good do
if chat == v.Good[i] then
print(v.Bad[math.random(1,#v.Bad)])
end
end
for p = 1,#v.Bad do
if chat == v.Bad[p] then
print(v.Good[math.random(1,#v.Good)])
end
end
end
end)
end)
To see if a word is listed instead of looping so much?
I feel like it’d make the script look cleaner:
game.Players.PlayerAdded:Connect(function(plr)
local tab = {
Word1 = {Good = "Alr", Bad = "NO"},
Word2 = {Good = {"Apple","Orange"}, Bad = {"Are bad","NO ew..", "Nope."}}
}
plr.Chatted:Connect(function(chat)
for _,v in pairs(tab) do
if table.find(v.Good, chat) then
print(v.Bad[math.random(1,#v.Bad)])
elseif table.find(v.Bad, chat) then
print(v.Good[math.random(1,#v.Good)])
end
end
end)
end)
Just a small detail, but personally it makes the code seem cleaner.
Other than that, yeah, it works.
game.Players.PlayerAdded:Connect(function(plr)
local tab = {
Word1 = {Good = "Alr", Bad = "NO"},
Word2 = {Good = {"Apple","Orange"}, Bad = {"Are bad","NO ew..", "Nope.","Veg","Dope"}}
}
plr.Chatted:Connect(function(chat)
for _,v in pairs(tab) do
if table.find(v.Good, chat) then
print(v.Bad[math.random(1,#v.Bad)])
elseif table.find(v.Bad, chat) then
print(v.Good[math.random(1,#v.Good)])
end
end
end)
end)
local filterWords = {
filterWords1 = {
word = {"words", "words", "words", "words",
replace = "words", "words", "words", "words", "words", "words", "words", "words"}
},
filterWords2 = {
words = {"words",
replace = "words"},
},
filterWords3 = {
words = {"words",
replace = "words"},
},
}
for index, catergory in pairs(filterWords) do
print(catergory)
for i = 1, #catergory.word do -- this is the line with the error
print(i)
if messageObject.Message == catergory.word[i] then
end
end
end
local filterWords = {
filterWords1 = {
words = {"words", "words", "words", "words"},
replace = {"words", "words", "words", "words", "words", "words", "words", "words"}
},
filterWords2 = {
words = {"words"},
replace = {"words"}
},
filterWords3 = {
words = {"words"},
replace = {"words"}
},
}
for index, catergory in pairs(filterWords) do
print(catergory)
for i = 1, #catergory.word do -- this is the line with the error
print(i)
if table.find(catergory.words,messageObject.Message) then
print(catergory.replace)
end
end
end