Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my Anti Cursing script not working properly?

Asked by 9 years ago

I have conducted a few tests to see what the problem is, but I can't see any problems nor why it is doing this, there is no Output either so I am very confused on how to fix it, the problem is the Count is not going up, it's just keeping at '1' count, and the script can not kick a Player when it wont do the counts, here is the script;

local Swears = {"Test"}
local MaxWarnings = 5
local Banland = {}

function ChkChat(str)
for i = 1, #Swears do if str:lower() == Swears[i]:lower() then return true elseif str:lower():find(Swears[i]:lower()) then return true end end
return false
end

function ChkBan(plr)
for i = 1, #Banland do if plr:lower() == Banland[i]:lower() then return true end end
return false
end

function Message(msg,par)
local M = Instance.new("Hint",par)
for i = 1, #msg do
M.Text = M.Text .. msg:sub(i,i)
wait(1/44)
end
wait(#msg/19+2.5)
if M then
M:Destroy()
end
end

function AntiSwear(plr,msg)

local Limit = 0 --Heres the count

if tostring(msg):lower() ~= "" then --This is where it'll check the chat, I know, it looks messy ;-;
if Limit >= MaxWarnings and ChkChat(msg) then --If Limit is over or equal to MaxWarnings then
print("Banned")
table.insert(Banland,plr.Name)
coroutine.wrap(function() repeat wait(.1) plr:LoadCharacter() until not plr end)()
elseif Limit < MaxWarnings and ChkChat(msg) then --If there are MaxWarnings over Limit then
Limit = Limit + 1 --Here's where it adds the count, but for some reason it only adds it once, and then doesn't add anymore
if plr and plr:FindFirstChild("PlayerGui") then
Message("You have a count of "..Limit..", "..MaxWarnings-Limit.." more and you will be banned",plr.PlayerGui)
end
end
end

end

function SystemControl(plr)
coroutine.wrap(function() if ChkBan(plr.Name) then repeat wait(.1) plr:LoadCharacter() until not plr end end)()
plr.Chatted:connect(function(msg) AntiSwear(plr,msg) end)
end

game.Players.PlayerAdded:connect(SystemControl)
for i,v in pairs(game.Players:GetPlayers()) do SystemControl(v) end

Answer this question