Roblox Server Sided Anti Cheat [Fly, Teleportation, JumpPower, WalkSpeed] (Search Engine)
Here’s a quick little script I wrote together for my future portfolios, free to use.
Note: It’s not meant to be pretty and if you find any problems comment on the thread and I’ll fix it.
Server Script (Parent Of Configuration Module)
-- // Written By .sinkz / Sinkl0z
-- // Variables
local Configuration = require(script.Configuration)
local PlayerFlags = {}
local PlayerThreads = {}
local OldPlayerPositions = {}
local NewPlayerPositions = {}
game.Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
-- // Begin
PlayerFlags[Player] = 0
local HumanoidRootPart = Character.HumanoidRootPart
-- // Create a Player specific thread for each player in the server upon join
PlayerThreads[Player] = task.spawn(function()
-- // Short yield to make sure Player loaded
task.wait(3)
while true do
-- // Store old Positions
OldPlayerPositions[Player] = {
X = HumanoidRootPart.Position.X,
Y = HumanoidRootPart.Position.Y,
Z = HumanoidRootPart.Position.Z,
}
task.wait(0.5)
-- // Store new Positions
NewPlayerPositions[Player] = {
X = HumanoidRootPart.Position.X,
Y = HumanoidRootPart.Position.Y,
Z = HumanoidRootPart.Position.Z,
}
-- // Y Position changes
if
NewPlayerPositions[Player].Y - OldPlayerPositions[Player].Y > 0 and
math.abs(NewPlayerPositions[Player].Y - OldPlayerPositions[Player].Y) >= Configuration.Numbers.JumpHeightLimit + Configuration.Numbers.JunpHeightThreshold
then
HumanoidRootPart.CFrame = CFrame.new(OldPlayerPositions[Player].X, OldPlayerPositions[Player].Y, OldPlayerPositions[Player].Z)
PlayerFlags[Player] += 1
end
-- // X - Z Position changes
if
math.abs(NewPlayerPositions[Player].X - OldPlayerPositions[Player].X) >= Configuration.Numbers.WalkSpeedLimit + Configuration.Numbers.WalkSpeedThreshold or
math.abs(NewPlayerPositions[Player].Z - OldPlayerPositions[Player].Z) >= Configuration.Numbers.WalkSpeedLimit + Configuration.Numbers.WalkSpeedThreshold
then
HumanoidRootPart.CFrame = CFrame.new(OldPlayerPositions[Player].X, OldPlayerPositions[Player].Y, OldPlayerPositions[Player].Z)
PlayerFlags[Player] += 1
end
-- // Punishment
if PlayerFlags[Player] >= Configuration.Numbers.MaximumFlags then
if Configuration.Booleans.KickPlayer then
-- // Kicks Player
Player:Kick("Abnormal Position Changes")
else
-- // Kills / Resets Player
if Character.Head then
Character.Head:Destroy()
PlayerFlags[Player] = 0
else
Character.Parent = nil
task.wait(2)
Character.Parent = workspace
PlayerFlags[Player] = 0
end
end
end
-- // Reset stored Positions
table.clear(OldPlayerPositions[Player])
table.clear(NewPlayerPositions[Player])
end
end)
end)
end)
game.Players.PlayerRemoving:Connect(function(Player)
-- // Clear all Player specific stored values (Important to prevent memory leaks)
PlayerFlags[Player] = 0
NewPlayerPositions[Player] = 0
OldPlayerPositions[Player] = 0
task.cancel(PlayerThreads[Player])
PlayerThreads[Player] = nil
end)
ConfigurationModule(Child Of Server Script)
local ConfigurationModule = {
Numbers = {
WalkSpeedLimit = 16,
WalkSpeedThreshold = 2,
JumpHeightLimit = 50,
JunpHeightThreshold = 2,
MaximumFlags = 6,
},
Booleans = {
KickPlayer = true,
},
}
return ConfigurationModule