This code serves as an **anti-cheat handler** for a Roblox...
This code serves as an anti-cheat handler for a Roblox game. The purpose of the script is to monitor and regulate player behavior, identifying and addressing suspicious activities such as teleportation, excessive movement speed, or leaving the designated map area. It also manages temporary bans for rule violations. Here's a detailed breakdown of what the code does:
Key Functionalities:
-
Privilege Checking for Owners/Moderators:
- The
OwnerIds
andModIds
tables list user IDs that are exempt from Anti-Cheat restrictions (e.g., game creators or trusted moderators). - The
isPrivileged
function checks whether a player's user ID is in these tables and skips all anti-cheat monitoring for those users.
- The
-
Temporary Ban System:
- Players who violate certain rules (e.g., leaving the map repeatedly or cheating) get temporarily banned for a configurable duration (
BAN_DURATION
, default is 12 hours). - This is managed using Roblox's
DataStoreService
to save and persist bans across game sessions. - The
isBanned
function checks if a player is temporarily banned upon joining, and if so, kicks them from the game with a message.
- Players who violate certain rules (e.g., leaving the map repeatedly or cheating) get temporarily banned for a configurable duration (
-
Out of Bounds Detection:
- The game considers the area defined by
SAFE_CENTER
andSAFE_RADIUS
as the safe play zone. - If a player moves significantly beyond this area (above
SAFE_RADIUS + OUT_OF_BOUNDS
), their humanoid's health is reduced to 0, effectively killing them in-game. - Repeated violations (more than 4) result in kicks, and 8 violations lead to a temporary ban.
- The game considers the area defined by
-
Teleportation Detection:
- The script tracks player positions (
LastPositions
) and checks if the distance between two consecutive positions exceedsMAX_TELEPORT
(the maximum allowed movement in one second). - Players who teleport (exceeding
MAX_TELEPORT
) are immediately kicked from the game.
- The script tracks player positions (
-
Excessive Speed Detection:
- Tracks the player's movement over a rolling 60-second window using
MovementHistory
. - Using this history, the script sums up the total distance moved in the last 60 seconds. If the total exceeds
MAX_DISTANCE_PER_MIN
(default is 70 studs), the player is kicked for "moving too far too quickly."
- Tracks the player's movement over a rolling 60-second window using
-
Player Monitoring:
- Each player's position, movement speed, and violations are monitored in real-time upon joining and spawning their character.
- Violations (e.g., leaving the map or teleporting) are counted (
Violations
table), and actions (e.g., kicking or banning) are escalated depending on the number of infractions.
-
Logging:
- The
log
function generates warnings in the server output for all significant actions, such as bans, kicks, or detected rule violations.
- The
-
Automatic Cleanup:
- Older movement records (
MovementHistory
) are cleaned up regularly to only store data from the last 60 seconds. - Expired bans are automatically removed when players try to join after their ban duration has elapsed.
- Older movement records (
Use Case:
The script is ideal for detecting and addressing common cheating methods, such as:
- Speed hacks: Moving faster than allowed (
MAX_DISTANCE_PER_MIN
). - Teleport hacks: Instantaneously moving a large distance between ticks (
MAX_TELEPORT
). - Leaving the map: Exceeding the predefined boundary (
SAFE_RADIUS + OUT_OF_BOUNDS
).
Flow of Events:
-
Player Joins:
- The script checks if the player is banned. If banned, they are kicked. Otherwise, the player is monitored.
-
Character Added:
- A new thread starts to monitor the player's
HumanoidRootPart
position every second. - Violations are tracked and handled (kicking or banning as needed).
- A new thread starts to monitor the player's
-
Violation Actions:
- Going Out of Bounds: Kills the player and tracks the number of violations; kicks or bans after repeated offenses.
- Teleporting: Kicks the player immediately if illegal teleportation is detected.
- Excessive Movement: Kicks the player for moving too far within a 60-second window.
Final Notes:
This script is designed to be placed in the ServerScriptService
of a Roblox game to secure the server from cheating or exploiting behaviors. It uses server-side checks to ensure that client-based hacks have minimal impact, and any suspicious activity results in immediate disconnection or banning from the game.