The biggest source of false positives though is just going to be internet latency. It would be better to divide the distance traveled by the timestep argument supplied to Heartbeat. Unfortunately, it is going to often be more than one second, so the error will be in favor of a false positive detection. For example, wait(1) doesn’t wait exactly 1 second, not with enough reliability to assume 1 second as the denominator of a velocity calculation. There are also some subtle problems with this particular implementation. Happy anti- hacking!Ī system that uses a single datapoint like this is going to have a potentially unacceptable degree of false positives that could result in game-breaking unnecessary “corrections” in the case of something like an obby. If you want to make your own anti-hax, now you know where to begin! If you need help, just ask. To get around this, disable the script for a few seconds while legitimately teleporting players. This is why we do not kick the player if the are detected hacking! It can generate false positives on slow connections.Unfortunately, using this method to detect speed hacking does come with a few drawbacks: Lastly, we actually record the player’s CFrame! Very simple. This will prevent any rage you might get from false positives. Instead of kicking the player like most anti-hax folks would be tempted to do, we just move them to the last good position they were in. This will print the name of our potential hacker… root.Parent:SetPrimaryPartCFrame(lastcf) If it is, we might have a hacker on our hands! print("Hack detected for "."!") Lastly, we check if that value is greater than maxspeed. We then round our results with math.floor so that we don’t get weird numbers like 16.4555~ or something. We only read the data we have on the X and Z axes so we don’t get a false positive when the player falls.
The actual logic! We are comparing the distance of the last known CFrame of the player to their current position. if math.floor((Vector3.new(lastcf.p.X, 0, lastcf.p.Z) - Vector3.new(, 0, )).magnitude) > maxspeed then This is how often we will compare the player’s position. It looks messy here, but I will decipher it line-by-line so you can understand what is going on! First: while wait(checktime) do Lastcf = root.CFrame -We store the player's position so we can see if they're hacking later! Instead, we peacefully move them back to their last known valid position! Root.Parent:SetPrimaryPartCFrame(lastcf) -The player is hacking! Because this could be a false positive, we DO NOT KICK THE PLAYER. See how we ignored the Y axis in the calculation? Also notice how we rounded on the line above? This prevents an inaccurate reading.
If it's greater than maxspeed, they're hacking. )).magnitude) > maxspeed then -We compare the length of the last known position, lastcf.p, with the current position, root.Position. If math.floor((Vector3.new(lastcf.p.X, 0, lastcf.p.Z) - Vector3.new(, 0, Now, for the actual checking, add this beneath your variables: while wait(checktime) do This is because we might get false positives from slower players who are still moving at 16 WalkSpeed but appear to be moving slightly faster to the server. They need to stay somewhat proportional to each other, or we might get false readings!Īlso note how I didn’t make maxspeed 17, directly above the default 16 WalkSpeed. Note the values for maxspeed and checktime. Local lastcf = root.CFrame -We will store the player's CFrame so that we can move the player there if they seem to be hacking. Local root = script.Parent:WaitForChild("HumanoidRootPart") -Get HumanoidRootPart so we can keep track of the player's position. If we make checktime too fast, like ".1", the script will be recording positions too fast and thus will fail to work correctly!
Local checktime = 1 -How many seconds we wait before we record their speed. Let’s add some variables first: local maxspeed = 22 -The maximum distance the player can travel within a check time. To begin, place a script into StarterCharacterScripts. We cannot rely on properties like WalkSpeed or Velocity to catch a hacker, but we can compare their positions to see if they’re cheating! Don’t freak out if that sounds too complex for you, because it’s actually really easy. If a player seems to be moving too fast, we stop them. The best way to detect a speed hacker is to check their location on the server. This means we need a way to detect ALL speed hacks, not just a specific method of doing it. The most basic hack could alter the player’s WalkSpeed, and more advanced hacks can change their FPS. Before we can stop speed hackers, we need to know how they speed hack in the first place! The truh is, there’s no single way people do this.