I don’t completely understand as to why this error appears in the output, can someone explain to me how and why this is happening?
-- Error:
Players.jaidon11.Backpack.ForbiddenWordsV2:6: missing argument #2
'Players.jaidon11.Backpack.ForbiddenWordsV2', Line 6
-- Script:
local ForbiddenWords = {"toast","cheese"}
function Detect(UI)
UI.Changed:Connect(function(Property)
if tostring(Property) == "Text" then
if string.match(string.lower(UI.Text),table.find(ForbiddenWords)) then -- THIS IS LINE 6
UI.Text = "[ Forbidden Word ]"
end
end
end)
end
table.find() uses 2 arguments, the first one is the table you want to find the value in, the second one is the value you want to find, on the 6th line youre missing the second argument in table.find(ForbiddenWords), anyways heres the fixed script:
-- Script:
local ForbiddenWords = {"toast","cheese"}
function Detect(UI)
UI:GetPropertyChangedSignal("Text"):Connect(function() --// :GetPropertyChangedSignal is a shorter way of using .Changed
if table.find(ForbiddenWords, string.lower(UI.Text)) then
UI.Text = "[ Forbidden Word ]"
end
end)
end
The issue is table.find. You did not say what you’re trying to find! Use this code instead:
local ForbiddenWords = {"toast","cheese"}
local function Detect(UI) -- only call this function once
UI.Changed:Connect(function(Property)
if tostring(Property) == "Text" then
for _, word in pairs(ForbiddenWords) do
if string.match(string.lower(UI.Text), word) then
UI.Text = "[ Forbidden Word ]"
end
end
end
end)
end