Why NaN positions get past Roblox distance checks
A client can send its character's position as NaN, and every comparison with NaN is false. How to write reach and speed checks that refuse it.
What it looks like
A server reach or movement check reads the character's position and rejects the action when the distance is too large. An exploiter's client owns its character, so it can send a position that is NaN. Every comparison with NaN is false, so distance > reach never rejects and the action goes through from anywhere.
if (root.Position - chest.Position).Magnitude > reach then return end
What an exploiter could do
They set their character's position to NaN for a moment and fire the remote. Every reach check written as a rejection passes, so they collect, open, buy or hit things from anywhere on the map. One NaN step also switches off a speed check that stores the last position unconditionally, and they can then move as fast as they like for the rest of the session.
How to fix it
- Write every limit as an acceptance:
if not (distance <= reach) then return end. NaN fails it, and so does infinity. - Only store a position as the last good one when it passes the check, and check it's finite first.
position.Magnitude < math.hugeis false for NaN and infinity. - When a reading isn't finite, move the character back to its last good position rather than trusting or storing it.
Vulnerable example
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") local Workspace = game:GetService("Workspace") local reach = 12 local ores = Workspace:WaitForChild("Ores") local lastPosition: { [Player]: Vector3 } = {} ReplicatedStorage.Remotes.MineOre.OnServerEvent:Connect(function(player: Player, ore: unknown) if typeof(ore) ~= "Instance" or not ore:IsA("BasePart") or ore.Parent ~= ores then return end local character = player.Character if not character or (character:GetPivot().Position - ore.Position).Magnitude > reach then return end ore:Destroy() player:SetAttribute("Ore", (tonumber(player:GetAttribute("Ore")) or 0) + 1) end) RunService.Heartbeat:Connect(function(delta) for _, player in Players:GetPlayers() do local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart") if root and root:IsA("BasePart") then local previous = lastPosition[player] lastPosition[player] = root.Position if previous and (root.Position - previous).Magnitude > 50 * delta then root.CFrame = CFrame.new(previous) end end end end) Players.PlayerRemoving:Connect(function(player) lastPosition[player] = nil end)
Fixed example
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") local Workspace = game:GetService("Workspace") local reach = 12 local ores = Workspace:WaitForChild("Ores") local lastPosition: { [Player]: Vector3 } = {} ReplicatedStorage.Remotes.MineOre.OnServerEvent:Connect(function(player: Player, ore: unknown) if typeof(ore) ~= "Instance" or not ore:IsA("BasePart") or ore.Parent ~= ores then return end local character = player.Character if not character or not ((character:GetPivot().Position - ore.Position).Magnitude <= reach) then return end ore:Destroy() player:SetAttribute("Ore", (tonumber(player:GetAttribute("Ore")) or 0) + 1) end) RunService.Heartbeat:Connect(function(delta) for _, player in Players:GetPlayers() do local root = player.Character and player.Character:FindFirstChild("HumanoidRootPart") if root and root:IsA("BasePart") then local position = root.Position local previous = lastPosition[player] if not previous then if position.Magnitude < math.huge then lastPosition[player] = position end elseif (position - previous).Magnitude <= 50 * delta then lastPosition[player] = position else root.CFrame = CFrame.new(previous) end end end end) Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function() lastPosition[player] = nil end) end) Players.PlayerRemoving:Connect(function(player) lastPosition[player] = nil end)
How to spot this in your own scripts, and the cases that only look like it, are part of the Luaudit check your AI runs.