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.