Anti-Teleport Exploit giving false positive's

Hey there, I’m working on implementing a server-side anti-exploit for teleporting, however it kept giving off false positives and essentially breaking the game. It would become so much for the server, that people couldn’t even press the initial “Play” button

this is the code:

game.Players.PlayerAdded:Connect(function(plr)
	
	plr.CharacterAdded:Connect(function(char)
		
		local hrp = char:WaitForChild("HumanoidRootPart")
		hrp:GetPropertyChangedSignal("CFrame"):Wait()
		local Hum = char:WaitForChild("Humanoid",15)
		
		local lastCF = hrp.CFrame
		local lastGroundedCF = hrp.CFrame
		local lastGrounded = tick()
		local interval = 1
		local punishment = 1
		game:GetService("RunService").Heartbeat:Connect(function(step)
			
			local cf = hrp.CFrame
			local currPos = hrp.Position
			wait(interval)
			local nowPos = hrp.Position
			local distMoved = nowPos-currPos

			local maxMovable = interval*Hum.WalkSpeed


			if distMoved.X > (maxMovable+22) or distMoved.X < -(maxMovable+22) or distMoved.Z > (maxMovable+22) or distMoved.Z < -(maxMovable+22) then

				hrp.CFrame = lastCF
				end
			
		end)
	end)
end)

I just don’t quite understand why it’s giving off false positives.

Usually when people spawn in, they can get about the max studs and then it teleports them back. Looking for literally anything to help solve this issue.

1 Like

Why are you creating a new connection bound to Heartbeat FOR EACH CHARACTER?? This is exactly how you destroy your game with memory leaks.

If I needed to review my faulty code, this is where I would start. It looks super messy and confusing. And what’s stopping you from just using disMoved.Magnitude >= maxMovable, a single simple condition?

Another important note, usually for teleportation checks you will want to go up a few derivatives and check for acceleration or even jolt rather than velocity or just position. Players can naturally achieve high velocities via game mechanics such as driving a fast car or falling off a cliff, which can explain the huge amount of false positives; but it is improbable to achieve a high acceleration by natural means unless the player was launched from a cannon.