How to check headshots on the server in Roblox

A headshot bonus based on the part the client names makes every shot a headshot. How to score hits from the server's own raycast.

warningLuaudit check: client-chosen-hit-parts

What it looks like

A weapon deals extra damage for a headshot, a weak spot or armour it ignores, and the server takes the client's word for which part was hit. The client sends the part, its name, the material or a flag such as isHeadshot, and the server checks the target was in range or in sight, but not that the shot landed on that part.

Luau
remote.OnServerEvent:Connect(function(player, victim, part)
	if canHit(player, victim) then
		local damage = if part.Name == "Head" then 100 else 35
		victim.Humanoid:TakeDamage(damage)
	end
end)

What an exploiter could do

Every shot counts as a headshot or a weak-spot hit. Weapons that take several body shots to kill take one, and bosses with armoured phases go down as fast as the weak spot allows, at whatever rate the weapon fires.

How to fix it

  • Raycast on the server from the attacker's own character in the direction the client sent, and base the damage on RaycastResult.Instance, its name or RaycastResult.Material.
  • If the server keeps the client's chosen part, raycast from the attacker's head to that part's position and only use it when the result's Instance is that part. Otherwise score it as a body shot.
  • Keep the damage table for each part on the server. Never take a multiplier from the client.

Vulnerable example

Vulnerable
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local range = 200
local bodyDamage = 30
local headDamage = 90
local cooldown = 1
local lastShot: { [Player]: number } = {}

ReplicatedStorage.Remotes.FireBow.OnServerEvent:Connect(function(player: Player, victim: unknown, isHeadshot: unknown)
	if typeof(victim) ~= "Instance" or not victim:IsA("Model") or typeof(isHeadshot) ~= "boolean" then
		return
	end
	local character = player.Character
	local root = character and character:FindFirstChild("HumanoidRootPart")
	local targetRoot = victim:FindFirstChild("HumanoidRootPart")
	local humanoid = victim:FindFirstChildOfClass("Humanoid")
	if not character or victim == character or not character:FindFirstChild("Bow") then
		return
	end
	if not root or not root:IsA("BasePart") or not targetRoot or not targetRoot:IsA("BasePart") or not humanoid or humanoid.Health <= 0 then
		return
	end
	local now = os.clock()
	if now - (lastShot[player] or -math.huge) < cooldown then
		return
	end
	if not ((targetRoot.Position - root.Position).Magnitude <= range) then
		return
	end
	lastShot[player] = now
	humanoid:TakeDamage(if isHeadshot then headDamage else bodyDamage)
end)

Players.PlayerRemoving:Connect(function(player)
	lastShot[player] = nil
end)

Fixed example

Fixed
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Workspace = game:GetService("Workspace")

local range = 200
local bodyDamage = 30
local headDamage = 90
local cooldown = 1
local lastShot: { [Player]: number } = {}

ReplicatedStorage.Remotes.FireBow.OnServerEvent:Connect(function(player: Player, direction: unknown)
	if typeof(direction) ~= "Vector3" or not (direction.Magnitude > 0 and direction.Magnitude < math.huge) then
		return
	end
	local character = player.Character
	local head = character and character:FindFirstChild("Head")
	if not character or not head or not head:IsA("BasePart") or not character:FindFirstChild("Bow") then
		return
	end
	local now = os.clock()
	if now - (lastShot[player] or -math.huge) < cooldown then
		return
	end
	lastShot[player] = now
	local params = RaycastParams.new()
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = { character }
	local result = Workspace:Raycast(head.Position, direction.Unit * range, params)
	if not result then
		return
	end
	local victim = result.Instance:FindFirstAncestorOfClass("Model")
	local humanoid = victim and victim:FindFirstChildOfClass("Humanoid")
	if humanoid and humanoid.Health > 0 then
		humanoid:TakeDamage(if result.Instance.Name == "Head" then headDamage else bodyDamage)
	end
end)

Players.PlayerRemoving:Connect(function(player)
	lastShot[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.