Hello everyone, I actually made this script for someone but they have never returned to me and I didn’t give either so I wanted to post it in here and have your feedback.
Module:
-- Services
local dataStoreService = game:GetService("DataStoreService")
local banStore = dataStoreService:GetDataStore("BanList")
local data
local succ, err = pcall(function()
local dataStoreData = banStore:GetAsync("a$%324k2}*124.£#1$")
if dataStoreData then
dataStoreData = data
print("Loaded the data.")
else
data = {}
print("No data - default one loaded.")
end
end)
if succ then
print("Banned list successfully received to server.")
else
print("Fail for receiving banned list.")
warn(err)
end
local module = {}
module.getBanned = function()
return data
end
module.ban = function()
local banCmds = {}
-- Event for banning
local event = Instance.new("BindableEvent")
banCmds.Changed = event.Event
banCmds.updateBanned = function()
local succ0, err0 = pcall(function()
banStore:SetAsync(data, "a$%324k2}*124.£#1$")
end)
if succ0 then
print("Successfully updated ban list.")
else
print("An error was occuired while trying to update ban list.")
warn(err0)
end
end
banCmds.add = function(plr)
local lastIndex
for i, v in pairs (data) do
lastIndex = i
end
print(lastIndex)
if lastIndex == nil then lastIndex = 0 end
table.insert(data, lastIndex+1, plr.UserId)
banCmds.updateBanned()
event:Fire(0)
plr:Kick("Banned for exploiting. Contact game adminsration if you think this is wrong.")
end
banCmds.remove = function(plr)
local lastIndex
for i, v in pairs (data) do
if v == plr.UserId then
lastIndex = i
end
end
table.remove(data, i)
banCmds.updateBanned()
event:Fire(1)
end
return banCmds
end
module.humanoidJumpCheck = function(plr)
local char = plr.Character
local torso = char:FindFirstChild("Torso")
local hum = char:FindFirstChild("Humanoid")
local torsoPos = torso.Position
local trig = os.time()
repeat wait() until hum:GetState() == Enum.HumanoidStateType.Freefall
repeat wait() until hum:GetState() == Enum.HumanoidStateType.Landed
local newPos = torso.Position
local rate = (newPos - torsoPos).Magnitude * (os.time() - trig)
if rate > 150 then
plr:Kick("Suspicious client activity has been detected.")
end
end
module.CheckChar = function(char)
local HRP = char:FindFirstChild("HumanoidRootPart")
local Torso = char:FindFirstChild("Torso")
local Humanoid = char:FindFirstChild("Humanoid")
local plr = game.Players:GetPlayerFromCharacter(char)
if HRP and Torso and Humanoid then
return
else
plr:Kick("An unexpected error has occuired.")
end
end
module.HumStateCheck = function(plr)
local char = plr.Character
local hum = char:FindFirstChild("Humanoid")
local state = hum:GetState()
if state == Enum.HumanoidStateType.StrafingNoPhysics then
local ban = module.ban()
ban.add(plr)
end
end
module.checkTPandFly = function(plr)
while wait(1) do
local char = plr.Character
if char then
local hrp = char:FindFirstChild("HumanoidRootPart")
if hrp then
local pos = hrp.Position
pos = Vector3.new(pos.X, pos.Y, 0)
wait(1)
local newPos = hrp.Position
newPos = Vector3.new(newPos.X, newPos.Y, 0)
if (pos - newPos).Magnitude > 30 then
plr:Kick("Suspicious client activity has been detected.")
end
end
end
end
end
module.checkGodMode = function(plr, health)
local hum = plr.Character:FindFirstChild("Humanoid")
if health > 100 then
local ban = module.ban()
ban.add(plr)
end
end
return module
ServerScript:
-- Services
local players = game:GetService("Players")
-- Event
local banned
game.Players.PlayerAdded:Connect(function(plr)
local module = require(script.AntiCheatModule)
repeat wait() until banned
local function banCheck(plr)
local id = plr.UserId
for _, v in pairs (banned) do
if v == id then
plr:Kick("Permanently banned, can't connect the game.")
return
end
end
print("Player is not banned.")
end
banCheck(plr)
plr.CharacterAdded:Connect(function(char)
local function checkCharParts(plr)
module.CheckChar(plr.Character)
end
local function humStateCheck(plr)
module.HumStateCheck(plr)
end
local function checkTPandFly(plr)
module.checkTPandFly(plr)
end
local function humanoidJumpCheck(plr)
module.humanoidJumpCheck(plr)
end
local function checkGodMode(plr,health)
module.checkGodMode(plr, health)
end
local function charAdded(plr, char)
local hum = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
char.DescendantRemoving:Connect(function()
checkCharParts(plr)
end)
hum.StateChanged:Connect(function(old, new)
humStateCheck(plr)
if new == Enum.HumanoidStateType.Jumping then
humanoidJumpCheck(plr)
end
end)
hrp:GetPropertyChangedSignal("CFrame"):Connect(function() --May cause overload
wait(2)
checkTPandFly(plr)
end)
hum.HealthChanged:Connect(function(health)
if health > 100 then
checkGodMode(plr, health)
end
end)
end
charAdded(plr, char)
end)
plr:LoadCharacter()
end)
local module = require(script.AntiCheatModule)
wait()
banned = module.getBanned()
if banned then
print("ServerScript has received the banned list.")
else
print("Banned list couldn't be loaded to the server.")
end
game:BindToClose(function()
local ban = module.ban()
ban.updateBanned()
end)
Known issues:
- Module breaks some other scripts in game.
- Bans don’t save.