Headshots not working

I’m trying to make a gun which can do headshots and bodyshots. But this doesn’t work. Here is my code:

local raycastparams = RaycastParams.new()
	raycastparams.FilterDescendantsInstances = {player.Character}
	raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
	
	local raycastResult = workspace:Raycast(script.Parent.Handle.Position,(mousePos - script.Parent.Handle.Position)*300,raycastparams)
	
	if raycastResult then
		sound.Playing = true
		
		script.Parent.Handle.Hole.Flash.Enabled = true
		
		local hitPart = raycastResult.Instance
		local model = hitPart:FindFirstAncestorOfClass("Model")
		
		if model then
			if model:FindFirstChild("Humanoid") then
				if hitPart.Name == "Head" then
					model.Humanoid.Health -= 75
				else
					model.Humanoid.Health -= 50
				end
			end
		end
	end

Just do:

if hitPart.Name == "Head" then
    local humanoid = hitPart.Parent:FindFirstChild("Humanoid")
    humanoid:TakeDamage(dmg)
end
1 Like